当前位置:网站首页>TZC 1283: simple sort - select sort
TZC 1283: simple sort - select sort
2022-07-26 05:17:00 【Orange teacher】
We use TZC 1283 As an example, briefly explain the sorting ( Including ten classic sorting algorithms ) Of python Implementation method and C Implementation method . During comparison and sorting , Hold down a certain number and compare it with all the following numbers , If the former is greater than the latter , Then exchange , Obviously, there are many times to exchange in the process of comparison and sorting , The ideal way is to press and hold a certain number , Then find the minimum value in all the following numbers, and then compare and Exchange , In this way, the number of exchanges will be reduced .
Original link :1283: Simple order

python The code is as follows :
# Selection sort
def choose_sort(lst):
for a in range(0, len(lst) - 1):
p = a
for b in range(a+1, len(lst)):
if lst[p] > lst[b]:
p = b
if p != a:
t = lst[p]
lst[p] = lst[a]
lst[a] = t
T = int(input())
for i in range(T):
s = input().split()
lt = [int(x) for x in s]
lt1 = lt[::-1]
lt1.pop()
n = len(lt1)
choose_sort(lt1)
for j in range(n):
if j != n - 1:
print(lt1[j], end=' ')
else:
print(lt1[j])

C The language code is as follows :
#include <stdio.h>
void choosesort(int x[],int n) // Selection sort
{
int i,j,p,temp;
for(i=0;i<n-1;i++)
{
p=i;
for(j=i+1;j<n;j++)
{
if(x[p]>x[j])
{
p=j;
}
}
if(p!=i)
{
temp=x[p];
x[p]=x[i];
x[i]=temp;
}
}
}
int main()
{
int m,n,i,j,a[1000]={0};
scanf("%d",&m);
while(m--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
choosesort(a,n);
for(i=0;i<n-1;i++)
printf("%d ",a[i]);
printf("%d\n",a[n-1]);
}
return 0;
}
边栏推荐
- Embedded development notes, practical knowledge sharing
- I talked with the interviewer about MySQL optimization in five dimensions
- Migrate the server and reconfigure the database (the database has no monitoring, and the monitoring starts with tns-12545, tns-12560, tns-00515 errors)
- Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output
- 新人如何做好功能测试,学会这几项够用了
- Shell的read 读取控制台输入、read的使用
- Excel VBA: realize automatic drop-down filling formula to the last line
- NetCore MySql The user specified as a definer (‘admin‘@‘%‘) does not exist
- Chinese character style transfer --- learn the conversion and generation of one to many programmed Chinese characters through generation confrontation network
- Map making of environmental impact assessment based on remote sensing interpretation and GIS technology
猜你喜欢

真正的科学减肥

MySQL basic learning
![[acwing] 1268. Simple questions](/img/f3/7eeae566dd74d77cf6f8b4640e4f29.png)
[acwing] 1268. Simple questions

Week 6 Learning Representation: Word Embedding (symbolic →numeric)

MODFLOW Flex、GMS、FEFLOW、HYDRUS实践应用

ALV report flow diagram

C语言函数

如何优雅的复现YOLOv5官方历程(二)——标注并训练自己的数据集

使用Ansible中的playbook

Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output
随机推荐
LeetCode链表问题——206.反转链表(一题一文学会链表)
MySQL基础学习
no networks found in /etc/cni/net.d
Black eat black? The man cracked the loopholes in the gambling website and "collected wool" for more than 100000 yuan per month
C language force buckle question 42 of rain. Four methods - violence, dynamic planning, stack, double pointer
Practical technology of SWAT Model in simulation of hydrology, water resources and non-point source pollution
真正的科学减肥
35. 搜索插入位置
ALV报表流程图解
Your understanding of the "happen before principle" may be wrong?
Meta analysis [whole process, uncertainty analysis] method based on R language and meta machine learning
Shell流程控制(重点)、if 判断、case 语句、let用法、for 循环中有for (( 初始值;循环控制条件;变量变化 ))和for 变量 in 值 1 值 2 值 3… 、while 循环
【Leetcode】493. Reverse Pairs
ABAP语法学习(ALV)
DOM事件流 事件冒泡-事件捕获-事件委托
Week 6 Learning Representation: Word Embedding (symbolic →numeric)
C语言详解系列——函数的认识(4)函数的声明与定义,简单练习题
ALV report flow diagram
Week 6 Learning Representation: Word Embedding (symbolic →numeric)
SAP报表开发步骤