编写程序,建立一个有3个节点的单向链表,每个节点包含名字,年龄,工资。编写函数creat,
编写程序,建立一个有3个节点的单向链表,每个节点包含名字,年龄,工资。编写函数creat,#include<stdio.h>#include<malloc.h>#defi...
编写程序,建立一个有3个节点的单向链表,每个节点包含名字,年龄,工资。编写函数creat,#include <stdio.h>
#include<malloc.h>
#define stu struct student
stu
{
char name[20];
int age
int wage
stu next
};
stu *creat(void)
{
}
vold output( stu *p)
{
while (p ! =NULL)
{
printf( '' %s:",p-<name);
printf(age=%d wage=%d\n, P->age, p->wage );
p=p->next;
}
}
vold main()
{
stu *p
p =creat();
output(p);
} 展开
#include<malloc.h>
#define stu struct student
stu
{
char name[20];
int age
int wage
stu next
};
stu *creat(void)
{
}
vold output( stu *p)
{
while (p ! =NULL)
{
printf( '' %s:",p-<name);
printf(age=%d wage=%d\n, P->age, p->wage );
p=p->next;
}
}
vold main()
{
stu *p
p =creat();
output(p);
} 展开
2018-06-15
展开全部
你那个next需是指针,*next,
h = (struct student *)malloc(sizeof(struct student)); int i=1;
p1 = p2 = h;
while(i<3)
{p1=p2;
p2=p1->next;
p2= (struct student *)malloc(sizeof(struct student)
}
h = (struct student *)malloc(sizeof(struct student)); int i=1;
p1 = p2 = h;
while(i<3)
{p1=p2;
p2=p1->next;
p2= (struct student *)malloc(sizeof(struct student)
}
展开全部
#include <stdio.h>
#include <malloc.h>
#define stu struct student
stu
{ char name[20];
int age;
int wage;
stu *next;
};
stu *creat( void )
{ stu *p,*q,*h;
int i;
for(i=0; i<3; i++)
{ p=(stu*)malloc(sizeof(stu));
scanf("%s%d%d",p->name,&(p->age),&(p->wage));
if(i==0)h=q=p;
else q->next=p,q=p;
}
q->next=NULL;
return h;
}
void output( stu *p )
{ while ( p != NULL )
{ printf( "%s: ", p->name );
printf( "age=%d wage=%d", p->age, p->wage );
p = p->next;
}
}
int main()
{ stu *p;
p = creat( );
output( p );
}
#include <malloc.h>
#define stu struct student
stu
{ char name[20];
int age;
int wage;
stu *next;
};
stu *creat( void )
{ stu *p,*q,*h;
int i;
for(i=0; i<3; i++)
{ p=(stu*)malloc(sizeof(stu));
scanf("%s%d%d",p->name,&(p->age),&(p->wage));
if(i==0)h=q=p;
else q->next=p,q=p;
}
q->next=NULL;
return h;
}
void output( stu *p )
{ while ( p != NULL )
{ printf( "%s: ", p->name );
printf( "age=%d wage=%d", p->age, p->wage );
p = p->next;
}
}
int main()
{ stu *p;
p = creat( );
output( p );
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
h = (struct student *)malloc(sizeof(struct student));
int i=1;
p1 = p2 = h;
while(i<3)
{p1=p2;
p2=p1->next;
p2= (struct student *)malloc(sizeof(struct student)
p1 = p2 = h;
while(i<3)
{p1=p2;
p2=p1->next;
p2= (struct student *)malloc(sizeof(struct student)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询