zoukankan
html css js c++ java
实验十 链表
1、
#include
<
stdio.h
>
#include
<
stdlib.h
>
void
main()
{
int
*
a,
*
b,
*
c,
*
min;
a
=
(
int
*
)malloc(
sizeof
(
int
));
b
=
(
int
*
)malloc(
sizeof
(
int
));
c
=
(
int
*
)malloc(
sizeof
(
int
));
min
=
(
int
*
)malloc(
sizeof
(
int
));
printf(
"
输入三个整数:
"
);scanf(
"
%d %d %d
"
,a,b,c);
printf(
"
输出这三个整数:%d %d %d \n
"
,
*
a,
*
b,
*
c);
*
min
=*
a;
if
(
*
a
>*
b)
*
min
=*
b;
if
(
*
a
>*
c)
*
min
=*
c;
printf(
"
输出最小整数:%d\n
"
,
*
min);
free(a);free(b);free(c);free(min);
}
2、
#include
<
stdio.h
>
#include
<
stdlib.h
>
struct
list
{
char
data;
struct
list
*
next;
}
;
struct
list
*
create()
{
struct
list
*
h,
*
p,
*
q;
char
ch;
h
=
(
struct
list
*
)malloc(
sizeof
(
struct
list));
p
=
q
=
h;
ch
=
getchar();
while
(ch
!=
'
?
'
)
{
p
=
(
struct
list
*
)malloc(
sizeof
(
struct
list));
p
->
data
=
ch;
q
=
p;
ch
=
getchar();
}
p
->
next
=
NULL;
return
h;
}
void
main()
{
}
3、
#include
<
stdio.h
>
#include
<
stdlib.h
>
#include
<
conio.h
>
#include
<
ctype.h
>
#define
LEN sizeof(struct student)
struct
student
{
long
num;
char
name[
20
];
float
score[
3
];
struct
student
*
next;
}
;
int
n;
struct
student
*
create()
{
struct
student
*
h,
*
p,
*
q;
n
=
0
;h
=
NULL;
p
=
(
struct
student
*
)malloc(LEN);
scanf(
"
%ld %s %f %f %f
"
,
&
p
->
num,p
->
name,
&
p
->
score[
0
],
&
p
->
score[
1
],
&
p
->
score[
2
]);
p
->
next
=
NULL;
while
(p
->
num
!=
0
)
{
++
n;
if
(n
==
1
) h
=
p;
else
q
->
next
=
p;
q
=
p;
p
=
(
struct
student
*
)malloc(LEN);
scanf(
"
%ld %s %f %f %f
"
,
&
p
->
num,p
->
name,
&
p
->
score[
0
],
&
p
->
score[
1
],
&
p
->
score[
2
]);
p
->
next
=
NULL;
}
free(p);
return
(h);
}
void
print(
struct
student
*
head)
{
struct
student
*
p;
printf(
"
\n现在共有%d个学生信息:\n
"
,n);
p
=
head;
if
(head
!=
NULL)
do
{
printf(
"
学号\t姓名\t语文\t数学\t英语\n
"
);
printf(
"
%ld\t%s\t%.2f\t%.2f\t%.2f\n
"
,p
->
num,p
->
name,p
->
score[
0
],p
->
score[
1
],p
->
score[
2
]);
p
=
p
->
next;
}
while
(p
!=
NULL);
}
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
(head
==
p1) head
=
p0;
else
p2
->
next
=
p0;
p0
->
next
=
p1;
}
else
{p1
->
next
=
p0;p0
->
next
=
NULL;}
}
++
n;
return
head;
}
struct
student
*
del(
struct
student
*
head,
long
num)
{
struct
student
*
p1,
*
p2;
if
(head
==
NULL)
{
printf(
"
\n无学生信息!\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(
"
删除:%ld\n
"
,num);
free(p1);
n
--
;
}
else
printf(
"
无学号%ld记录!\n
"
,num);
end:
return
head;
}
struct
student
*
find(
struct
student
*
head,
long
num)
{
struct
student
*
p1,
*
p2;
if
(head
==
NULL)
{
printf(
"
\n无学生信息!\n
"
);
goto
end;
}
p1
=
head;
while
(num
!=
p1
->
num
&&
p1
->
next
!=
NULL)
{p2
=
p1;p1
=
p1
->
next;}
if
(num
==
p1
->
num)
printf(
"
查找结果:%ld\t%s\t%.2f\t%.2f\t%.2f\n
"
,num,p1
->
name,p1
->
score[
0
],p1
->
score[
1
],p1
->
score[
2
]);
else
printf(
"
没有发现%ld学生记录!\n
"
,num);
end:
return
head;
}
void
main()
{
struct
student
*
head,
*
stu;
long
find_num,del_num;
char
letter;
printf(
"
请输入学生信息(学号为0结束):\n
"
);
head
=
create();
print(head);
do
{
printf(
"
A 插入学生信息\n
"
);
printf(
"
B 查找学生信息\n
"
);
printf(
"
C 删除学生信息\n
"
);
printf(
"
Q 退出\n
"
);
printf(
"
请选择: \n
"
);
letter
=
getch();
letter
=
toupper(letter);
switch
(letter)
{
case
'
A
'
:
printf(
"
请输入要插入的学生信息:\n
"
);
stu
=
(
struct
student
*
)malloc(LEN);
scanf(
"
%ld %s %f %f %f
"
,
&
stu
->
num,stu
->
name,
&
stu
->
score[
0
],
&
stu
->
score[
1
],
&
stu
->
score[
2
]);
head
=
insert(head,stu);
print(head);
break
;
case
'
B
'
:
printf(
"
请输入要查找的学生学号:\n
"
);
scanf(
"
%ld
"
,
&
find_num);
head
=
find(head,find_num);
//
print(head);
break
;
case
'
C
'
:
printf(
"
请输入要删除的学生学号:\n
"
);
scanf(
"
%ld
"
,
&
del_num);
head
=
del(head,del_num);
print(head);
break
;
}
}
while
(letter
!=
'
Q
'
);
}
查看全文
相关阅读:
服务注册发现Eureka之二:高可用服务注册中心
可重入锁 公平锁 读写锁、CLH队列、CLH队列锁、自旋锁、排队自旋锁、MCS锁、CLH锁
红黑树(Red-Black tree)
fuser 命令小结
客户端负载均衡Ribbon之三:AvailabilityFilteringRule的坑(Spring Cloud Finchley.SR2)
mysql重复记录的查询删除方法
innodb的锁、update单条记录的花费时间压测
被kill问题之1:进程物理内存远大于Xmx的问题分析
服务注册发现Eureka之三:Spring Cloud Ribbon实现客户端负载均衡(客户端负载均衡Ribbon之三:使用Ribbon实现客户端的均衡负载)
十二、jdk工具之jcmd介绍(堆转储、堆分析、获取系统信息、查看堆外内存)
原文地址:https://www.cnblogs.com/qixin622/p/651408.html
最新文章
[转]angular2在运行ng serve的时候卡在95% emitting LicenseWebpackPlugin
[转]angular2封装material2对话框组件
[转]Angular2 Material2 封装组件 —— confirmDialog确定框
[转]angular2中ng alerts的使用教程
[转]angular2之@Output() EventEmitter
[转]JS实现千分位
[转]Angular2 使用管道Pipe以及自定义管道格式数据
[转]Angular2: Cannot read property 'name' of undefined
[转]GIT 常用命令
angular
热门文章
[转]Angular——提示框
[转]基于boot2docker部署Docker环境
[转]docker-compose教程(安装,使用, 快速入门)
[转]完整记录在 windows7 下使用 docker 的过程
[转]window7下利用DockerToolbox安装Docker
[转]使用docker-compose 大杀器来部署服务 上
cpu监控之三:mpstat命令
linux中uptime命令查看linux系统负载
Linux系统中的load average
RocketMQ之一:RocketMQ整体介绍
Copyright © 2011-2022 走看看