c语言实现链表的输入
#include<stdio.h>#include<malloc.h>#include<stdlib.h>voidmain(){typedefstructnode_typ...
#include<stdio.h>
#include<malloc.h>
#include <stdlib.h>
void main()
{ typedef struct node_type
{ int d;
struct node_type*next;
}node_type;
typedef struct list_type
{ node_type*head;
node_type*tail;
int length;
}list_type;
node_type*new_node,*p;
list_type list;
list.length=0;
list.head=NULL;
list.tail=NULL;
new_node=malloc(sizeof(struct node_type));
scanf("%d",&new_node->d);
while(new_node->d>=0)
{
if(list.length<=0)
{ list.head=new_node;
list.tail=new_node;
}
else
{ new_node->next=list.tail->next;
list.tail->next=new_node;
}
list.length=list.length+1;
new_node=malloc(sizeof(struct node_type));
scanf("%d",&new_node->d);
}
p=list.head;
while(p!=NULL)
{printf("%d ",p->d);
p=p->next;}
}
输出不太对,刚学链表,求大神指点,多谢 展开
#include<malloc.h>
#include <stdlib.h>
void main()
{ typedef struct node_type
{ int d;
struct node_type*next;
}node_type;
typedef struct list_type
{ node_type*head;
node_type*tail;
int length;
}list_type;
node_type*new_node,*p;
list_type list;
list.length=0;
list.head=NULL;
list.tail=NULL;
new_node=malloc(sizeof(struct node_type));
scanf("%d",&new_node->d);
while(new_node->d>=0)
{
if(list.length<=0)
{ list.head=new_node;
list.tail=new_node;
}
else
{ new_node->next=list.tail->next;
list.tail->next=new_node;
}
list.length=list.length+1;
new_node=malloc(sizeof(struct node_type));
scanf("%d",&new_node->d);
}
p=list.head;
while(p!=NULL)
{printf("%d ",p->d);
p=p->next;}
}
输出不太对,刚学链表,求大神指点,多谢 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询