日复一日

厚积薄发|跳跃的人生

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

2006年6月17日

摘要: 在双向链表中删除指定元素。 1void del(List head, List node){ 2 List pre=new List(); 3 pre.next = head; 4 List cur = head; 5 while(cur && cur!=node){ 6 cur=cur.next; 7 pre=pre.next; 8 }... 阅读全文
posted @ 2006-06-17 08:53 GwQ 阅读(787) 评论(0) 推荐(0) 编辑

摘要: 用一个数据结构实现 1if (x == 0) y = a;2else y = b; 1j[] = {a,b};2y=j[x]; 阅读全文
posted @ 2006-06-17 08:53 GwQ 阅读(748) 评论(0) 推荐(0) 编辑

摘要: 将长型转换为字符串。 1char* ltoa(long l){ 2 char[N] str; 3 int i=1,n=1; 4 while(!(l/i<10)){i*=10;++n} 5 char* str=(char*)malloc(n*sizeof(char)); 6 int j=0; 7 while(l){ 8 str[j++]=l/i;... 阅读全文
posted @ 2006-06-17 08:52 GwQ 阅读(740) 评论(2) 推荐(0) 编辑

摘要: 两个链表,一升一降。合并为一个升序链表。 1 List merge(List a, List d) { 2 List a1 = reverse(d); 3 List p = q = new List(); 4 while ( a && a1 ) { 5 if (a.value < a1.value) { 6 ... 阅读全文
posted @ 2006-06-17 08:52 GwQ 阅读(755) 评论(4) 推荐(0) 编辑

摘要: 返回一颗二叉树的深度。 1int depth(Tree t){2 if(!t) return 0;3 else {4 int a=depth(t.right);5 int b=depth(t.left);6 return (a>b)?(a+1):(b+1);7 }8} 阅读全文
posted @ 2006-06-17 08:51 GwQ 阅读(680) 评论(0) 推荐(0) 编辑

摘要: 判断一颗二叉树是否平衡。 1int isB(Tree t){2 if(!t) return 0;3 int left=isB(t.left);4 int right=isB(t.right);5 if( left >=0 && right >=0 && left - right =-1)6 return (left<right)? (right +1) : (... 阅读全文
posted @ 2006-06-17 08:51 GwQ 阅读(648) 评论(0) 推荐(0) 编辑

摘要: 一个数组,下标从0到n,元素为从0到n的整数。判断其中是否有重复元素。 1int hasDuplicate(int[] a, int n){ 2 for(int i=0;i<n;++i){ 3 while(a[i]!=i && a[i]!=-1){ 4 if(a[a[i]]==-1) return 1; 5 a[i]=a[a[i]]... 阅读全文
posted @ 2006-06-17 08:50 GwQ 阅读(734) 评论(1) 推荐(0) 编辑

摘要: 在一个链表中删除另一个链表中的元素。 1void delete(List m, List n) { 2 if(!m || !n) return; 3 List pre = new List(); 4 pre.next=m; 5 List a=m, b=n,head=pre; 6 while(a && b){ 7 if(a.value b.value)... 阅读全文
posted @ 2006-06-17 08:50 GwQ 阅读(681) 评论(0) 推荐(0) 编辑

摘要: 三柱汉诺塔最小步数。 1 int f3(n) { 2 if (f3[n]) return f3[n]; 3 else { 4 if (n == 1 ) { 5 f3[n] = 1 ; 6 return 1 ; 7 } 8 f3[n] = 2 * f... 阅读全文
posted @ 2006-06-17 08:49 GwQ 阅读(725) 评论(0) 推荐(0) 编辑

摘要: 汉诺塔问题。 1void tower(n,x,y,z){2 if(n==1) move(x,z);3 else {4 tower(n-1, x,z,y);5 move(x,z);6 tower(n-1, y,x,z);7 }8} 阅读全文
posted @ 2006-06-17 08:49 GwQ 阅读(794) 评论(0) 推荐(0) 编辑