Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
帮忙。。谢谢设计一个链表,先把N 个 2x+1顺序存进去,再按大小插入3x+1,并把后面的节点释放。 打印最后一个节点的值。。。 为什么??? #include <stdlib.h> #include <stdio.h> typedef struct node* link; struct node{ int item; link next; }; main() { int i,n,x=0; int key=1; scanf("%d ", &n); link t=malloc(sizeof (node)); link a; link last; t=a; for(i=1;i<=n;i++) { list a->next=malloc(sizeof (node)); a=a->next; a->item=2*x+1; x++; } a=t; for(i=1;i<=n;i++) { t->item=3*key+1; a=a->next; if(a->item<t->item) { t=a->next; a->next=t->next; last=t; while(last->next->next) last->next=last->next->next; free(last->next->next); } } while(a->next) a=a->next; printf("%d\n", a->item); } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator