标题:单向链表哪里有问题?谢谢
取消只看楼主
captain2050
Rank: 2
等 级:论坛游民
帖 子:57
专家分:43
注 册:2016-7-15
结帖率:92.86%
 问题点数:0 回复次数:0 
单向链表哪里有问题?谢谢
程序代码:
#include<stdio.h>
#include<stdlib.h>

int main()
{
  struct new
  {
    int num;
    struct new *next;
  };
  struct new *first=NULL;
  struct new *current=NULL;
  struct new *last=NULL;

 

  first=malloc(sizeof(struct new));
  current=malloc(sizeof(struct new));
  last=malloc(sizeof(struct new));
  printf("please input the first number:");
  setbuf(stdin,NULL);
  scanf("%d",&first->num);
  current=first->next;

 

  while(1)
    {
      scanf("%d",&current->num);
      if(current->num==-1)  //输入-1表示结束
    {last->next==NULL;break;}
      last=current;
      current=malloc(sizeof(struct new));
      last->next=current;
      current->next=NULL;
    }
  current=first;
  do
    {
      printf("%d\n",current->num);
      current=current->next;
    }
  while(current);
   

}
搜索更多相关主题的帖子: struct new next NULL current 
2017-07-31 12:41



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-479725-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027313 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved