大虾们,看看我这个程序错在哪里了……#include "stdio.h"

[复制链接]
查看11 | 回复4 | 2010-5-23 09:52:33 | 显示全部楼层 |阅读模式
#include "stdio.h"
#include "malloc.h"
#define LEN sizeof(struct student)
struct student
{
int num;
char xm[20];
char xb;
int fs;
char dz[30];
struct student *next;
};
int n;
struct student *creat()
{ struct student *head;

struct student *p1,*p2;

n=0;

p1=p2=(struct student *) malloc(LEN);
printf("请输入数据:\n");

scanf("%d%s%c%d%s",&p1->num,&p1->xm,&p1->xb,&p1->fs,&p1->dz);

head=NULL;

while(p1->num!=0)

{n=n+1;
if(n==1) head=p1;
else p2->next=p1;

p2=p1;

p1=(struct student*)malloc(LEN);
scanf("%d%s%c%d%s",&p1->num,&p1->xm,&p1->xb,&p1->fs,&p1->dz);
}

p2->next=NULL;
return(head);
}
void print(struct student *head)
{
struct student *p;
p=head;
if(head!=NULL)

do{

printf("%d %s %c %d %s\n",p->num,p->xm,p->xb,p->fs,p->dz);

p=p->next;

}while(p!=NULL);
}
struct student *insert(struct student *head,struct student *nw)
{
struct student *p0,*p1,*p2;
p0=nw;
p1=head;
if(head==NULL)
{head=p0;p0->next=NULL;}
while((p0->num>p1->num)&&(p1->next!=NULL))
{p2=p1;p1=p1->next;}
if(p0->numnum)
{
if(head==p1)
head=p0;
else
p2->next=p0;
p0->next=p1;
}
else
{
p1->next=p0;p0->next=NULL;
}
n=n+1;
return(head);
}
void main()
{
struct student *head,*nw;
head=creat();
puts("请输入要插入新结点的数据:");
nw=(struct student *)malloc(LEN);
scanf("%d%s%s%d%s",&nw->num,&nw->xm,&nw->xb,&nw->fs,&nw->dz);
nw->next=NULL;
insert(head,nw);
puts("插入后新的数据为:\n");
print(head);
}
输入要插入的结点后,最后出不来结果……

回复

使用道具 举报

千问 | 2010-5-23 09:52:33 | 显示全部楼层
编译无错,你说到底什么问题?
回复

使用道具 举报

千问 | 2010-5-23 09:52:33 | 显示全部楼层
NO
回复

使用道具 举报

千问 | 2010-5-23 09:52:33 | 显示全部楼层
hhuy
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行