• 博客访问： 95314
• 博文数量： 23
• 博客积分： 516
• 博客等级： 中士
• 技术积分： 315
• 用 户 组： 普通用户
• 注册时间： 2011-10-29 16:45

2012年（11）

2011年（12）

2011-11-09 01:11:04

#include
#include

#define LEN sizeof(TypeStu)

typedef struct student
{
long num;
float score;
struct student *next;
}TypeStu;

int n;

TypeStu *creat(void)
{
TypeStu *p1,*p2;
n = 0;
if((p2=p1=(TypeStu *)malloc(LEN)) == NULL)
{
printf("malloc memory failure!\n");
}

scanf("%ld,%f",&p1->num,&p1->score);

while(p1->num!=0)
{
n++;
else p2->next = p1;
p2 = p1;
p1 = (TypeStu *)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
}
p2->next = NULL;
}

{
TypeStu *p1,*p2;
{
printf("\nlist null! \n");
}
while(num != p1->num && p1->next != NULL)
{
p2 = p1;
p1 = p1->next;
}
if(num == p1->num)
{
else p2->next = p1->next;
printf("delete:%ld\ n",num);
n = n-1;
}
else
{
printf("%ld not been found! \n",num);
}
}

{
TypeStu *p0,*p1,*p2;
p0 = stud;

{
p0->next = NULL;
}
else
{
while((p0->num > p1->num) && (p1->next != NULL))
{
p2 = p1;
p1 = p1->next;
}
if(p0->num <= p1->num)
{
else p2->next = p0;
p0->next = p1;
}
else
{
p1->next = p0;
p0->next = NULL;
}
}
n = n + 1;
}

{
TypeStu *p;
printf("\nNow,These %d records are:\n",n);
{
while(p!=NULL)
{
printf("%ld %f \n",p->num,p->score);
p = p->next;
}
}
}

void print_help()
{
printf("func = 1  ------>    call del function\n");
printf("func = 2  ------>    call insert function\n");
}

void main()
{
int func,Flg_exit = 0;
long del_num;
printf("input records:\n");

print_help();
printf("input operate function:");
scanf("%d",&func);
while(!Flg_exit)
{
switch(func)
{
case 1:
printf("\ninput the deleted number:");
scanf("%ld",&del_num);
while(del_num!=0)
{
printf("input the deleted number:");
scanf("%ld",&del_num);
}
break;

case 2:
printf("\ninput the inserted record:");
stu = (TypeStu *)malloc(LEN);
scanf("%ld,%f",&stu->num,&stu->score);
while(stu->num != 0)
{
printf("input the inserted record:");
stu = (TypeStu *)malloc(LEN);
scanf("%ld,%f",&stu->num,&stu->score);
}
break;

default:
printf("\nhave not the function and procedure exit\n\n");
Flg_exit = 1;
break;

}
if(!Flg_exit)
{
printf("\ninput operate function:");
scanf("%d",&func);
}
}
}

input records:
89,96
90,95
91,92
93,94
0

Now,These 4 records are:
89 96.000000
90 95.000000
91 92.000000
93 94.000000
func = 1  ------>    call del function
func = 2  ------>    call insert function
input operate function:1

input the deleted number:89
delete:89 n
Now,These 3 records are:
90 95.000000
91 92.000000
93 94.000000
input the deleted number:93
delete:93 n
Now,These 2 records are:
90 95.000000
91 92.000000
input the deleted number:0

input operate function:2

input the inserted record:89,96

Now,These 3 records are:
89 96.000000
90 95.000000
91 92.000000
input the inserted record:93,94

Now,These 4 records are:
89 96.000000
90 95.000000
91 92.000000
93 94.000000
input the inserted record:878,96

Now,These 5 records are:
89 96.000000
90 95.000000
91 92.000000
93 94.000000
878 96.000000
input the inserted record:0

input operate function:1

input the deleted number:878
delete:878 n
Now,These 4 records are:
89 96.000000
90 95.000000
91 92.000000
93 94.000000
input the deleted number:7
7 not been found!

Now,These 4 records are:
89 96.000000
90 95.000000
91 92.000000
93 94.000000
input the deleted number:0

input operate function:7

have not the function and procedure exit

0