当前位置:网站首页>7-2 keep the linked list in order
7-2 keep the linked list in order
2022-07-05 18:32:00 【mxrone】
For the information of several students entered , Establish an orderly linked list from small to large according to the student number , Finally, traverse the linked list , And output student information in order .
Input format :
First enter a positive integer T, Number of groups representing test data , And then there was T Group test data . First, input a positive integer for each group of test data n(1≤n≤100), Number of students . Then input n Line information , They are the student number and name of the student , among , The student number is 8 Bit positive integer ( Guarantees vary ), The name is no longer than 10 A string without spaces .
Output format :
For each group of tests , Output student information in order , Leave a space between student number and name ( See the output example ).
Input sample mile :
1
3
20080108 Zhangsan
20070328 Lisi
20070333 Wangwu
sample output :
20070328 Lisi
20070333 Wangwu
20080108 Zhangsan
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct stu{
int num;
char name[100];
struct stu *next;
};
int main(){
int n=0,m,i=0,j=0;
struct stu *head=NULL,*p,*tail,*q,*index,temp;
scanf("%d",&n);
while(i<n){
scanf("%d",&m);
for(j=0;j<m;j++){
p=(struct stu *)malloc(sizeof(struct stu ));
scanf("%d %s\n",&p->num,p->name);
if(head==NULL) head=tail=p;
else{
tail->next=p;
}
tail=p;
}
tail->next=NULL;
i++;
}
for(p=head;p!=NULL;p=p->next){
for(q=p->next;q!=NULL;q=q->next){
if(q->num<p->num){
temp.num=p->num;
strcpy(temp.name,p->name);
p->num=q->num;
strcpy(p->name,q->name);
q->num=temp.num;
strcpy(q->name,temp.name);
}
}
}
for(p=head;p!=NULL;p=p->next){
printf("%d %s\n",p->num,p->name);
}
return 0;
}
边栏推荐
- 文章中的逻辑词
- rust统计文件中单词出现的次数
- Copy the linked list with random pointer in the "Li Kou brush question plan"
- Tupu software digital twin | visual management system based on BIM Technology
- 【在優麒麟上使用Electron開發桌面應】
- Penetrate the whole intranet through socks agent
- Reptile 01 basic principles of reptile
- 兄弟组件进行传值(显示有先后顺序)
- 基于can总线的A2L文件解析(3)
- Is it complicated to open an account? Is online account opening safe?
猜你喜欢
第十届全球云计算大会 | 华云数据荣获“2013-2022十周年特别贡献奖”
如何获取飞机穿过雷达两端的坐标
Introduction to the development function of Hanlin Youshang system of Hansheng Youpin app
The 11th China cloud computing standards and Applications Conference | cloud computing national standards and white paper series release, and Huayun data fully participated in the preparation
To solve the stubborn problem of Lake + warehouse hybrid architecture, xinghuan Technology launched an independent and controllable cloud native Lake warehouse integrated platform
Memory leak of viewpager + recyclerview
Various pits of vs2017 QT
The 2022 China Xinchuang Ecological Market Research and model selection evaluation report released that Huayun data was selected as the mainstream manufacturer of Xinchuang IT infrastructure!
Share: ZTE Yuanhang 30 Pro root unlock BL magick ZTE 7532n 8040n 9041n brush mask original brush package root method Download
@Extension, @spi annotation principle
随机推荐
Is it safe to make fund fixed investment on access letter?
第十一届中国云计算标准和应用大会 | 华云数据成为全国信标委云计算标准工作组云迁移专题组副组长单位副组长单位
Penetrate the whole intranet through socks agent
Failed to virtualize table with JMeter
常见时间复杂度
Logical words in Articles
Introduction to VC programming on "suggestions collection"
[use electron to develop desktop on youqilin]
Memory management chapter of Kobayashi coding
Writing writing writing
Share: ZTE Yuanhang 30 Pro root unlock BL magick ZTE 7532n 8040n 9041n brush mask original brush package root method Download
Image classification, just look at me!
JVM third talk -- JVM performance tuning practice and high-frequency interview question record
7-2 保持链表有序
ConvMAE(2022-05)
[PM2 details]
Numerical calculation method chapter8 Numerical solutions of ordinary differential equations
Is it safe to open an account and register stocks for stock speculation? Is there any risk? Is it reliable?
To solve the stubborn problem of Lake + warehouse hybrid architecture, xinghuan Technology launched an independent and controllable cloud native Lake warehouse integrated platform
node_exporter内存使用率不显示