当前位置:网站首页>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;
}
边栏推荐
- 《力扣刷题计划》复制带随机指针的链表
- Multithreading (I) processes and threads
- JDBC reads a large amount of data, resulting in memory overflow
- 写作写作写作写作
- Sibling components carry out value transfer (there is a sequence displayed)
- 金太阳开户安全吗?万一免5开户能办理吗?
- [PM2 details]
- @Extension, @spi annotation principle
- vs2017 qt的各种坑
- Is it safe for Apple mobile phone to speculate in stocks? Is it a fraud to get new debts?
猜你喜欢
JVM third talk -- JVM performance tuning practice and high-frequency interview question record
Wu Enda team 2022 machine learning course, coming
吳恩達團隊2022機器學習課程,來啦
Simulate the hundred prisoner problem
pytorch yolov5 训练自定义数据
Memory leak of viewpager + recyclerview
案例分享|金融业数据运营运维一体化建设
To solve the stubborn problem of Lake + warehouse hybrid architecture, xinghuan Technology launched an independent and controllable cloud native Lake warehouse integrated platform
Pytorch yolov5 training custom data
MYSQL中 find_in_set() 函数用法详解
随机推荐
[QNX Hypervisor 2.2用户手册]6.3.2 配置VM
【HCIA-cloud】【1】云计算的定义、什么是云计算、云计算的架构与技术说明、华为云计算产品、华为内存DDR配置工具说明
Reading notes of Clickhouse principle analysis and Application Practice (5)
Memory leak of viewpager + recyclerview
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
【PaddlePaddle】 PaddleDetection 人脸识别 自定义数据集
Xiaobai getting started with NAS - quick building private cloud tutorial series (I) [easy to understand]
Nacos distributed transactions Seata * * install JDK on Linux, mysql5.7 start Nacos configure ideal call interface coordination (nanny level detail tutorial)
7-1 链表也简单fina
线性表——抽象数据类型
sample_rate(采样率),sample(采样),duration(时长)是什么关系
吳恩達團隊2022機器學習課程,來啦
Various pits of vs2017 QT
[QNX hypervisor 2.2 user manual]6.3.2 configuring VM
音视频包的pts,dts,duration的由来.
Record a case of using WinDbg to analyze memory "leakage"
About statistical power
LeetCode 6109. 知道秘密的人数
About Estimation with Cross-Validation
Use of websocket tool