关于链表的综合操作
来源:互联网 发布:体育科研数据分析 编辑:程序博客网 时间:2024/05/18 04:19
学习过程中写的,就当复习基础知识好了。
#include<stdio.h>
#include<malloc.h>
#define LEN sizeof(struct student)
//#define NULL 0
struct student
{
long num;
float score;
struct student *next;
};
int n;
struct student *creat(void) /*创建动态链表*/
{
struct student *p1,*p2,*head;
p1=p2=(struct student *) malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
n=0;
while(p1->num!=0)
{
n++;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=( struct student *)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
}
p2->next=NULL;
return head;
}
struct student *del(struct student *head,long num) //删除链表节点
{
struct student *p1,*p2;
if(head==NULL)
{
printf("空链表!/n");
return head;
}
p1=head;
while(p1->num!=num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(p1->num==num)
{
if(p1==head) head=p1->next;
else p2->next=p1->next;
printf("delete %d successfully!/n",num);
}
else printf("not found the num!");
return head;
}
struct student *insert(struct student *head,struct student *stud) //插入一个节点。
{
struct student *p0,*p1,*p2;
p1=head;
p0=stud;
if(head==NULL)
head=p0,p0->next=NULL;
else
{
while(((p0->num)>(p1->num))&&(p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}
if(p0->num<=p1->num)
{
if(p1==head) head=p0,p0->next=p1;
else p2->next=p0,p0->next=p1;
}
else
{
p1->next=p0;
p0->next=NULL;
}
}
return head;
}
void main()
{
long num;
struct student *p,*head,stud;
head=p=creat();
do
{
printf("%ld,%.2f/n",p->num,p->score);
p=p->next;
}
while(p!=NULL);
printf("input the num you want to delete:/n");
scanf("%ld",&num);
p=del(head,num);
do
{
printf("%ld,%.2f/n",p->num,p->score);
p=p->next;
}
while(p!=NULL);
printf("input the inserted record:/n");
scanf("%ld,%f",&stud.num,&stud.score);
p=insert(head,&stud);
do
{
printf("%ld,%.2f/n",p->num,p->score);
p=p->next;
}
while(p!=NULL);
}
- 关于链表的综合操作
- l链表的综合操作
- 对链表的综合操作
- 链表的综合操作(重新整理,模块一点)
- P305_1111链表的综合操作,建表、…
- 关于gridview的操作技巧背景颜色等综合设置
- 堆的综合操作
- C语言链表综合操作
- 关于对日期操作得综合类
- 链表的综合使用
- 链表的综合运用
- 关于Verilog的综合~转载
- 实战数据结构(7)_线性表的综合操作
- 反射对属性操作的综合案例
- CString 操作指南、 CString_string_char的综合比较
- Java操作excel的综合应用(jxl)
- 对PV操作问题的理解综合
- 关于堆和栈的综合例子
- 【转】Android平台简介
- 关云长~
- android应用内调用其它android应用
- silverlight性能测试
- Ant的使用
- 关于链表的综合操作
- c# 获取网页源码
- 图片切换
- hdoj(hdu)-3487-play with the chain-SplayTree
- VC:CString用法整理(转载)
- VS2008中装AjaxToolkit
- 软件测试
- iphone开发总结1
- 从Windows下安装SUSE Linux