当前位置:网站首页>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;
}
边栏推荐
- [QNX Hypervisor 2.2用户手册]6.3.2 配置VM
- ConvMAE(2022-05)
- 吴恩达团队2022机器学习课程,来啦
- [paddleclas] common commands
- Einstein sum einsum
- node_ Exporter memory usage is not displayed
- The 10th global Cloud Computing Conference | Huayun data won the "special contribution award for the 10th anniversary of 2013-2022"
- 案例分享|金融业数据运营运维一体化建设
- Privacy computing helps secure data circulation and sharing
- U-Net: Convolutional Networks for Biomedical Images Segmentation
猜你喜欢
Wu Enda team 2022 machine learning course, coming
@Extension、@SPI注解原理
Maximum artificial island [how to make all nodes of a connected component record the total number of nodes? + number the connected component]
Nacos distributed transactions Seata * * install JDK on Linux, mysql5.7 start Nacos configure ideal call interface coordination (nanny level detail tutorial)
Take a look at semaphore, the current limiting tool provided by JUC
Failed to virtualize table with JMeter
Pytorch yolov5 training custom data
Various pits of vs2017 QT
Fix vulnerability - mysql, ES
Vulnhub's darkhole_ two
随机推荐
Logical words in Articles
ClickHouse(03)ClickHouse怎么安装和部署
What is the reason why the video cannot be played normally after the easycvr access device turns on the audio?
Is it complicated to open an account? Is online account opening safe?
Leetcode notes: Weekly contest 300
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!
写作写作写作写作
LeetCode 6109. Number of people who know the secret
Cronab log: how to record the output of my cron script
7-2 保持链表有序
The main thread anr exception is caused by too many binder development threads
Clickhouse (03) how to install and deploy Clickhouse
Problems encountered in the project u-parse component rendering problems
rust统计文件中单词出现的次数
vulnhub之darkhole_2
如何写出好代码 - 防御式编程
Image classification, just look at me!
IDEA配置npm启动
Nacos distributed transactions Seata * * install JDK on Linux, mysql5.7 start Nacos configure ideal call interface coordination (nanny level detail tutorial)
【在優麒麟上使用Electron開發桌面應】