当前位置:网站首页>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;
}
边栏推荐
- sample_rate(采樣率),sample(采樣),duration(時長)是什麼關系
- Use JMeter to record scripts and debug
- 线性表——抽象数据类型
- Writing writing writing
- 吳恩達團隊2022機器學習課程,來啦
- 爱因斯坦求和einsum
- Xiaobai getting started with NAS - quick building private cloud tutorial series (I) [easy to understand]
- How to improve the thermal management in PCB design with the effective placement of thermal through holes?
- What is the reason why the video cannot be played normally after the easycvr access device turns on the audio?
- JDBC reads a large amount of data, resulting in memory overflow
猜你喜欢

案例分享|金融业数据运营运维一体化建设

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

node_exporter内存使用率不显示

About Estimation with Cross-Validation

Pytorch yolov5 training custom data

Trust counts the number of occurrences of words in the file

To solve the stubborn problem of Lake + warehouse hybrid architecture, xinghuan Technology launched an independent and controllable cloud native Lake warehouse integrated platform

vs2017 qt的各种坑

Insufficient picture data? I made a free image enhancement software

Copy the linked list with random pointer in the "Li Kou brush question plan"
随机推荐
The easycvr platform reports an error "ID cannot be empty" through the interface editing channel. What is the reason?
让更多港澳青年了解南沙特色文创产品!“南沙麒麟”正式亮相
Is it safe to make fund fixed investment on access letter?
Can communication of nano
Deep copy and shallow copy [interview question 3]
lombok @Builder注解
彻底理解为什么网络 I/O 会被阻塞?
【PaddleClas】常用命令
文章中的逻辑词
如何获取飞机穿过雷达两端的坐标
第十届全球云计算大会 | 华云数据荣获“2013-2022十周年特别贡献奖”
Copy the linked list with random pointer in the "Li Kou brush question plan"
Record a case of using WinDbg to analyze memory "leakage"
个人对卷积神经网络的理解
Check namespaces and classes
【HCIA-cloud】【1】云计算的定义、什么是云计算、云计算的架构与技术说明、华为云计算产品、华为内存DDR配置工具说明
Access the database and use redis as the cache of MySQL (a combination of redis and MySQL)
Is it safe for Apple mobile phone to speculate in stocks? Is it a fraud to get new debts?
第十一届中国云计算标准和应用大会 | 华云数据成为全国信标委云计算标准工作组云迁移专题组副组长单位副组长单位
音视频包的pts,dts,duration的由来.