日复一日

厚积薄发|跳跃的人生

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

2006年6月17日

摘要: 求一个整形中1的位数。 1 int f( int x) {2 int n = 0 ;3 while (x) {4 ++ n;5 x &= x - 1 ;6 } 7 return n;8 } 阅读全文
posted @ 2006-06-17 08:34 GwQ 阅读(921) 评论(2) 推荐(0) 编辑

摘要: 实现strcmp函数。 1int strcmp(char* str1, char* str2){2 while(*str1 && *str2 && *str1==*str2){3 ++str1;4 ++str2;5 }6 return *str1-*str2;7} 阅读全文
posted @ 2006-06-17 08:33 GwQ 阅读(755) 评论(0) 推荐(0) 编辑

摘要: 反转一个字符串。 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 str[i] ... 阅读全文
posted @ 2006-06-17 08:32 GwQ 阅读(912) 评论(4) 推荐(0) 编辑

摘要: 实现strstr函数。 1int strstr(char[] str, char[] par){ 2 int i=0; 3 int j=0; 4 while(str[i] && str[j]){ 5 if(str[i]==par[j]){ 6 ++i; 7 ++j; 8 }else{ 9 ... 阅读全文
posted @ 2006-06-17 08:32 GwQ 阅读(768) 评论(0) 推荐(0) 编辑

摘要: 判断一个链表是否有循环。 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 e... 阅读全文
posted @ 2006-06-17 08:31 GwQ 阅读(981) 评论(6) 推荐(0) 编辑

摘要: 广度优先遍历二叉树。 1void 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 = ... 阅读全文
posted @ 2006-06-17 08:28 GwQ 阅读(2180) 评论(2) 推荐(0) 编辑

摘要: 反转一个链表。递归算法。 1List resverse(list l) {2 if(!l || !l.next) return l;3 4 List n = reverse(l.next);5 l.next.next = l;6 l.next=null;7 }8 return n;9} 阅读全文
posted @ 2006-06-17 08:28 GwQ 阅读(2401) 评论(0) 推荐(0) 编辑

摘要: 前段时间找工作,针对网上能搜集到的微软试题进行了准备。现分享如下,如有谬误,还希望希望朋友能多多指出。朋友们如果有其他未收录的题目,也可以在这里分享。1、反转一个链表。循环算法。 1List reverse(List l) { 2 if(!l) return l; 3 list cur = l.next; 4 list pre = l; 5 list tmp; 6 pre.next... 阅读全文
posted @ 2006-06-17 08:26 GwQ 阅读(5154) 评论(18) 推荐(0) 编辑