|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include "stdio.h"
#include"malloc.h"
#define EN sizeof(struct stud)//长度
void print(struct stud *p);//输出动态链表
int n;
struct stud
{
int shu;
struct stud *next;
};
void mian()
{
struct stud *chuang();//创建动态链表
struct stud *p;
p = chuang();
print(p);
}
struct stud *chuang()
{
struct stud *head;
struct stud *p1,*p2;
p1 = p2 = (struct stud *)malloc(EN);
scanf("%d",p1->shu);
head = 0;n=0;
while(p1->shu)
{
n++;
if(n==1)
{
head=p1;
}
else
{
p2->next=p1;
}
p2=p1;
p1 = (struct stud *)malloc(EN);
scanf("%d",p1->shu);
}
p2->next = 0;
return head;
}
void print(struct stud *p)
{
printf("%d\n",n);
while(p->shu)
{
printf("%d\n",p->shu);
p = p->next;
}
} |
|