链表问题,大家帮忙看看
程序代码:
/* Note:Your choice is C IDE */ #include<stdio.h> #include<stdlib.h> #include<malloc.h> typedef struct list { int date; struct list *next,*pre; }node,*link; link head=NULL,prelink; link bulid(int init) { link newlink=(link)malloc(sizeof(node)); newlink->date = init; if(head==NULL) { head = newlink; head->next = NULL; head->pre = NULL; prelink = newlink; } else { prelink->next = newlink; newlink->pre = prelink; newlink->next = NULL; prelink = newlink; } return head; } void display(link currlink) { link p; p=currlink; while(p!=NULL) { printf("%d->",p->date); p=p->next; } } void main() { link frist; int n,i; printf("input your first data!\n"); scanf("%d",&n); frist=bulid(n); for(i=0;i<3;i++) { printf("input:\n"); scanf("%d",&n); bulid(n); } display(frist); printf("\n"); display(frist); }链表进过一个display后不是跑到最后了吗?怎么第二次display有会从新开始?如果我要表链表跑到最后要怎么做?
[ 本帖最后由 hwf214685147 于 2012-2-10 14:58 编辑 ]