l链表的综合操作
来源:互联网 发布:spark金融数据分析 编辑:程序博客网 时间:2024/05/17 04:48
#define NULL 0
#define LEN sizeof(struct student)
struct student
{
long num;
long score;
struct student *next;
};
main(){
int j,listnum,delnum,n;
int num1=1000,score1=2000;
struct student *head,*p1,*p2;
/*生成链表。。。*/
printf("/nput in the length of the list: ");
scanf("%d",&listnum);
for(n=1;n<=listnum;n++){
p1=(struct student*)malloc(LEN);
p1->num=num1++; p1->score=score1++ ;
if(n==1) head=p2=p1;
else {p2->next=p1;p2=p1;}
}
p2->next=NULL;
printf("head: %0x,last:%0x/n",head,p1);/*链表生成结束*/
/*输出链表*/
p1=head;
printf("/nnow the new list is:/n");
for(n=1;n<=listnum;++n,p1=p1->next){
printf("/nn=%d,num=%ld,score=%ld/n",n,p1->num,p1->score);
}
/*删除一个节点*/
p1=head;
n=1;
do{
printf("/ndelete:put in the right order:from %d to %d/n",1,listnum);
scanf("%d",&j);
}while(j<1||j>listnum);/*从 1到listnum 有效*/
while(n<j){/*查找第j个元素,当n等于j时,跳出循环*/
p2=p1;p1=p1->next;++n;
}
if(j==1){
head=p1->next;
printf("the num:%ld,the score:%ld/n",p1->num,p1->score);
}
else{
p2->next=p1->next;
printf("/nyou have delete : num:%ld, score:%ld/n",p1->num,p1->score);
free(*p1);
}
--listnum;/*删除节点结束*/
/*输出节点*/
p1=head;
printf("/nnow the new list is:/n");
for(n=1;n<=listnum;++n){
printf("/nn=%d,num=%ld,score=%ld/n",n,p1->num,p1->score);
p1=p1->next;
}
/*插入一个节点*/
do{
printf("/n insert: put in the right order: from %d to %d/n",1,listnum+1);
scanf("%d",&j);
}while(j<1||j>listnum+1);/*从 1到listnum+1 有效*/
p1=head;
n=1;
while(n<j){p2=p1;p1=p1->next;n++;}
p1=(struct student*)malloc(LEN);
p1->num=num1++;p1->score=score1++;
if(j==1)
{p1->next=head;head=p1;}
else
{p1->next=p2->next;p2->next=p1;}
++listnum;/*插入节点结束*/
/*输出链表*/
p1=head;
printf("/nnow the new list is:/n");
for(n=1;n<=listnum;++n ){
printf("/nn=%d,num=%ld,score=%ld/n",n,p1->num,p1->score);
p1=p1->next;
}
scanf("%d",&j);
}
- l链表的综合操作
- 对链表的综合操作
- 关于链表的综合操作
- 链表的综合操作(重新整理,模块一点)
- P305_1111链表的综合操作,建表、…
- L脚本语言表对象的高级操作
- 堆的综合操作
- C语言链表综合操作
- l链表的数据类型
- 2.14-实现Length(L)返回链表L的长度
- 链表的综合使用
- 链表的综合运用
- 一个链表L 一个链表P 包含升序排列的整数 操作PrintLots(L,P)将打印L中那些由P所指定的位置上的元素
- 实战数据结构(7)_线性表的综合操作
- l链表的头插法和尾插法
- 目录操作/ls -l 命令的实现
- 图的操作和l邻接矩阵存储
- 反射对属性操作的综合案例
- vb.net常用函数
- Red Hat Linux 9.0 使用总结
- 比较Oracle SQL中的IN & EXISTS
- Kdevelop+QT
- 程序员不是神,态度决定一切
- l链表的综合操作
- 学习SQL应知道的动态SQL语句基本语法
- MS-SQL游标的使用及理解
- 史上最饶舌的绕口令
- 数字家园的宏观概念
- java程序的递归算法,列出某个目录下的所有子目录和文件
- 关于VS2003IDE的使用技巧大全 之(二)
- 链表的综合操作(重新整理,模块一点)
- CButton