|  | 
 
| 
while(head->next!=NULL)
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  {
 printf("%d  ",head->data);
 head=head->next;
 }
 用这段代码依次输出链表的元素   输入四个只能输出前三个
 while(head->next!=NULL)
 {
 printf("%d  ",head->next->data);
 head=head->next;
 }
 用这段代码依次输出链表的元素   输入几个最后一个输不出来
 下边是这段代码所在的函数,如果需要全部的话我再发,谢谢各位
 struct link *Num2(struct link *head)
 {
 struct link *temp,*tail;
 if(head == NULL)
 {
 printf("链表不存在!\n");
 exit(1);
 }
 else
 {
 while (1)
 {
 temp = (struct link*)malloc(sizeof(struct link));
 if(temp == NULL)
 {
 printf("内存分配失败!\n");
 exit(1);
 }
 else
 {
 printf("输入一个数:");
 scanf("%d",&temp->data);
 temp->next = NULL;
 if (temp->data == -1)
 break;
 if(head->next == NULL)
 head->next = temp;
 else
 tail->next = temp;
 }
 tail = temp;
 }
 tail->next = NULL;
 }
 while(head->next!=NULL)
 {
 printf("%d  ",head->data);
 head=head->next;
 }
 return head;
 }
 
 | 
 |