清_水
发表于 2014-5-18 16:54:29
贵。。。。。。
清_水
发表于 2014-5-19 21:26:35
堆了几天的鱼币瞬间就没有了好贵:cry
幸运的杨震
发表于 2014-5-31 20:40:25
22222222222222222222222222222222
小泉向西流
发表于 2014-6-5 17:18:22
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#define LEN sizeof(struct student)
struct student *creat(); //创建链表
struct student *del(struct student *head, int num); //del函数用于删除节点
struct student *insert(struct student *head, struct student *stu_2); /*插入一个节点, 第一个形参,待插入的链表, 第二个形参,待插入的结构的地址*/
void print(struct student *head); //打印链表, 可以不用参数
struct student
{
int num;
float score;
struct student *next;
};
int n;
void main()
{
struct student *stu, *p, *stu_2;
int del_num;
printf("input records!\n");
stu=creat();
p = stu;
print(p);
printf("\n");
printf("please input the num to delete:"); //删除
scanf("%d", &del_num);
while(del_num!=0) // 循环删除,0 退出
{
p=del(p,del_num);
print(p);
printf("please input the num to delete:");
scanf("%d", &del_num);
}
printf("\nplease input the record to insert: \n");//插入
stu_2=(struct student * )malloc(LEN);
printf("please input the num : ");
scanf("%d",&stu_2->num);
printf("please input the score : ");
scanf("%f",&stu_2->score);
while(stu_2->num!=0)
{
p=insert(stu,stu_2);
print(p);
printf("\nplease input the record to insert: \n");
stu_2=(struct student * )malloc(LEN);
printf("please input the num : ");
scanf("%d",&stu_2->num);
printf("please input the score : ");
scanf("%f",&stu_2->score);
}
printf("\n");
system("pause");
}
struct student *creat() //创建链表
{
struct student *head;
struct student *p1, *p2;
p1=p2=(struct student * )malloc(LEN); // LEN 是结构体 student 的长度大小
printf("please input the num : ");
scanf("%d",&p1->num);
printf("please input the score : ");
scanf("%f",&p1->score);
printf("\n");
head=NULL;
n=0;
while(p1->num!=0)
{
n=n+1;
if(n==1)
{
head=p2;
}
else
{
p2->next=p1;
}
p2=p1; //p2 指向表尾, p1为新建单元
p1=(struct student * )malloc(LEN);
printf("please input the num : ");
scanf("%d",&p1->num);
printf("please input the score : ");
scanf("%f",&p1->score);
printf("\n");
}
p2->next=NULL;
return head;
}
void print(struct student *head) //打印链表
{
struct student *p;
printf("\nThere are %d records!\n\n",n);
p=head;
if(head!=NULL)
{
do
{
printf("学号为 %d 的成绩为 %f \n", p->num, p->score);
p=p->next;
}while(p!=NULL);
}
}
struct student *del(struct student *head, int num) // 删除链表节点
{
struct student *p1, *p2;
if(head==NULL)
{
printf("\nList null\n");
goto end;
}
p1=head;
while(num!=p1->num && p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(num==p1->num)
{
if(p1==head) //要删的是头结点的时候
{
head=p1->next;
}
else
{
p2->next=p1->next;
}
printf("delete: No. %d succeed!\n", num);
n=n-1; //n是一个全局变量,记录存放了多少链表单元
}
else
{
printf("%d not been found! \n", num);
}
end:
return head;
}
struct student *insert(struct student *head, struct student *stu_2) //插入函数
{
struct student *p0,*p1, *p2;
p1=head;
p0=stu_2;
if(head==NULL)
{
head=p0;
p0->next=NULL;
}
else
{
while( (p0->num > p1->num) && (p1->next!=NULL) ) // 两种情况退出 while
{
p2=p1;
p1=p1->next;
}
if(p0->num <= p1->num)
{
if(head==p1)
{
head=p0;
}
else
{
p2->next=p0;
}
p0->next=p1;
}
else //p0的num最大,插在尾部
{
p1->next=p0;
p0->next=NULL;
}
n=n+1;
return head;
}
}
c语言,第十章第五节, 结构体与共用体,共057.
作业, 实现多次插入和多次删除。
Mikel
发表于 2014-6-5 20:08:17
淡定,淡定,淡定……
redcooper
发表于 2014-6-9 16:07:28
淡定,淡定,淡定……
燎火炙日
发表于 2014-6-19 20:56:55
我无语了……好贵啊。。
a1162645904
发表于 2014-6-20 21:15:23
淡定,淡定,淡定……
wangjianbo
发表于 2014-6-23 23:47:40
下了,看看。。。
Y丶
发表于 2014-7-4 18:50:35
没钱了:cry:cry:cry:cry:cry:cry:cry
dgjjxxm
发表于 2014-7-16 09:50:51
感恩无私的分享与奉献 :)
千寻0
发表于 2014-7-30 17:10:03
没有课题的源代码么。。。
千寻0
发表于 2014-7-30 17:13:59
没有看到源代码啊,
♂情︵☆缘★
发表于 2014-8-18 20:54:01
呜呜呜,没钱买呀
9990次想她
发表于 2014-8-27 10:16:48
我没鱼币啊
爱有你才完整
发表于 2014-9-23 22:48:57
我是VIP,我骄傲!
Laurence
发表于 2015-1-23 21:23:04
太贵了啊!太生气了,无法HOLD啦 >_<......
Mr.Evil
发表于 2015-3-10 09:39:31
xuexi
别走别忘
发表于 2015-5-4 11:51:13
谢谢老师上传!强烈支持楼主ing……
别走别忘
发表于 2015-5-4 11:51:48
好多鱼币啊!