22道数据结构算法面.pdf
《22道数据结构算法面.pdf》由会员分享,可在线阅读,更多相关《22道数据结构算法面.pdf(9页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、微软的 22 道数据结构算法面试题(含答案)1、反转一个链表。循环算法。1 List reverse(List l)2 if(!l)return l;3 list cur=l.next;4 list pre=l;5 list tmp;6 pre.next=null;7 while(cur)8 tmp=cur;9 cur=cur.next;10 tmp.next=pre;11 pre=tmp;12 13 return tmp;14 2、反转一个链表。递归算法。1 List resverse(list l)2 if(!l|!l.next)return l;3 4 List n=reverse(l.
2、next);5 l.next.next=l;6 l.next=null;7 8 return n;9 3、广度优先遍历二叉树。1 void BST(Tree t)2 Queue q=new Queue();3 q.enque(t);4 Tree t=q.deque();5 while(t)6 System.out.println(t.value);7 q.enque(t.left);8 q.enque(t.right);9 t=q.deque();10 11 -1class Node 2 Tree t;3 Node next;4 5class Queue 6 Node head;7 Node
3、tail;8 public void enque(Tree t)9 Node n=new Node();10 n.t=t;11 if(!tail)12 tail=head=n;13 else 14 tail.next=n;15 tail=n;16 17 18 public Tree deque()19 if(!head)20 return null;21 else 22 Node n=head;23 head=head.next;24 return n.t;25 26 4、输出一个字符串所有排列。注意有重复字符。1char p;2void perm(char s,int i,int n)3 i
4、nt j;4 char temp;5 for(j=0;jn;+j)6 if(j!=0&sj=sj-1);7 elseif(sj!=)8 pi=sj;9 sj=;10 if(i=n-1)11 pn=0;12 printf(%s,p);13 else 14 perm(s,i+1,n);文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8
5、 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B
6、8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6
7、B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S
8、6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5
9、S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X
10、5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8
11、X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G915 16 sj=pi;17 18 19-1void main()2 char sN;3 sort(s);4 perm(s,0,strlen(s);5 5、输入一个字符串,输出长型整数。1 long atol(char*str)2 char*p=str;3 long l=1;m=0;4 if(*p=-)5 l=-1;6+p;7 8 while(isDigit(*p)9 m=m*10+p;
12、10+p;11 12 if(!p)return m*l;13 else return error;14 6、判断一个链表是否有循环。1 int isLoop(List l)2 if(!l)return-1;3 List s=l.next;4 while(s&s!=l)5 s=s.next;6 7 if(!s)return-1;8 else reutrn 1;9 -1int isLoop(List l)文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8
13、D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V
14、8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5
15、V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M
16、5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7
17、M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW
18、7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:C
19、W7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G92 if(!l)return 0;3 p=l.next;4 wihle(p!=l&p!=null)5 l.next=l;6 l=p;p=p.next;7 8 if(p=l)return 1;9 return 0;10 实际上,在我的面试过程中,还问到了不破坏结构的其他
20、算法。我的答案是从链表头开始遍历,如果节点next 指针指向自身,则循环存在;否则将next 指针指向自身,遍历下一个节点。直至next 指针为空,此时链表无循环。7、反转一个字符串。1 void reverse(char*str)2 char tmp;3 int len;4 len=strlen(str);5 for(int i=0;i len/2;+i)6 tmp=char i;7 stri=strlen-i-1;8 strlen-i-1 =tmp;9 10 8、实现 strstr函数。1int strstr(char str,char par)2 int i=0;3 int j=0;4
21、while(stri&strj)5 if(stri=parj)6+i;7+j;8 else 9 i=i-j+1;10 j=0;11 12 13 if(!strj)return i-strlen(par);14 else return-1;15 文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:C
22、W7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:
23、CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码
24、:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编
25、码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档编码:CW7M5V8D4L10 HB10Z8X5S6B8 ZR9K5R8W10G9文档
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 22 数据结构 算法
限制150内