07 2012 档案

摘要:一直没有好好的扎扎实实的算法的基础,要找工作了,临时抱下佛脚,顺便把学的东西整理下,以应对比较健忘的大脑。。。废话不说,直接主题,其实整理这个,借鉴了不少这个blog,http://www.cppblog.com/shongbee2/archive/2009/04/25/81058.html在此再次感谢这个博主,但愿有一天,自己也能请博主喝杯咖啡 哈哈~先从最熟悉的冒泡排序开始吧:冒泡排序(BubbleSort)冒泡排序也是我接触到的最早的排序,其基本思想是把数组中每个元素都看成是有质量的气泡,每个气泡的质量就是数组对应位置的元素的大小。排序的过程就是不停的把质量较轻(元素较小)的气泡上浮的过 阅读全文
posted @ 2012-07-19 20:17 JWMNEU 阅读(245) 评论(0) 推荐(0)
摘要:Implement an algorithm to find the nth to last element of a singly linked list 分析:想法很简单,但是不是一下子就能想到的: 两个指针p1,p2分别指向头节点,然后让p1先循环n-1次,这样p1与p2 的间隔就是n-1,然后同时增加p1,p2,当p2到达尾节点的时候,p1正好到达倒数地n个节点。Linklist nthToLast(Linklist L,int n) { if(L==NULL||n<1) return NULL; Linklist p1=L; Linklist p2=L; for(int ... 阅读全文
posted @ 2012-07-18 21:29 JWMNEU 阅读(171) 评论(0) 推荐(0)
摘要:Write code to remove duplicates from an unsorted linked list FOLLOW UPHow would you solve this problem if a temporary buffer is not allowed?如果我们用缓冲区,我们可以在hash表里跟踪每一个元素,同时删除任何重复的。本文主要是记载线性表的一些实现方法。struct LNode { ElemType data; struct LNode *next; }; typedef struct LNode *Linklist;线性表的定义;void CreatL.. 阅读全文
posted @ 2012-07-18 20:43 JWMNEU 阅读(175) 评论(0) 推荐(0)
摘要:Write an algorithm such that if an element in an MxN matrix is 0, its entire row andcolumn is set to 0写一个算法使得把一个M*N的矩阵中0元素所在位置的行列设置为零At first glance, this problem seems easy: just iterate through the matrix and every time wesee a 0, set that row and column to 0 There’s one problem with that soluti.. 阅读全文
posted @ 2012-07-14 21:02 JWMNEU 阅读(234) 评论(0) 推荐(0)
摘要:Given an image represented by an NxN matrix, where each pixel in the imageis 4bytes, write a method to rotate the image by 90 degrees Can you do this in place?描述:给定一个N*N的图像,每个位置的像素是4byte,写一个方法用来在原来的空间内旋转图像90度。思路:我们可以按层来旋转。void matrixRotation(int [][]a,int n) { for(int layer=0;layer<n;layer++) { . 阅读全文
posted @ 2012-07-14 19:57 JWMNEU 阅读(333) 评论(0) 推荐(0)