c语言一道单向链表的改错题,例如输入1234560,则输出1,2,3,4,5,6.#include #include#includetypedef struct node{ int data; struct node *next;}NODE;#define LEN sizeof(NODE);NODE *setup(){ NODE *head=NULL,*p1,*p2; int n=0; p2=(NODE*)malloc(
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/07 14:40:14
c语言一道单向链表的改错题,例如输入1234560,则输出1,2,3,4,5,6.#include #include#includetypedef struct node{ int data; struct node *next;}NODE;#define LEN sizeof(NODE);NODE *setup(){ NODE *head=NULL,*p1,*p2; int n=0; p2=(NODE*)malloc(
c语言一道单向链表的改错题,例如输入1234560,则输出1,2,3,4,5,6.
#include
#include
#include
typedef struct node
{
int data;
struct node *next;
}NODE;
#define LEN sizeof(NODE);
NODE *setup()
{
NODE *head=NULL,*p1,*p2;
int n=0;
p2=(NODE*)malloc(LEN);
p1=p2;
scanf("%d",&p1->data);
p1->next=NULL;
while(p1->data)
{
n++;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(NODE*)malloc(LEN);
scanf("%d",&p1->data);
}
p2=NULL;
return head;
}
void main()
{
NODE *p;
p=setup();
while(p)
{
printf("%d",p->data);
p=p->next;
}
}
c语言一道单向链表的改错题,例如输入1234560,则输出1,2,3,4,5,6.#include #include#includetypedef struct node{ int data; struct node *next;}NODE;#define LEN sizeof(NODE);NODE *setup(){ NODE *head=NULL,*p1,*p2; int n=0; p2=(NODE*)malloc(
#define LEN sizeof(NODE); ---》#define LEN sizeof(NODE)