当前位置:网站首页>TZC 1283: simple sort Bubble Sort
TZC 1283: simple sort Bubble 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 . For bubble sorting principle, see :https://www.runoob.com/w3cnote/bubble-sort.html
In a word, it is : Compare two adjacent numbers , Large number of sinking bottom , Floating decimal .
Original link :1283: Simple order

Python The code is as follows :
# Bubble sort
def bubble_sort(lst):
for a in range(len(lst) - 1):
for b in range(len(lst)-1-a):
if lst[b] > lst[b+1]:
t = lst[b]
lst[b] = lst[b+1]
lst[b+1] = 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)
bubble_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 cmpsort(int x[],int n) // Bubble sort , From front to back , Large number of sinking bottom , From the back forward , Floating decimal
{
int i,j,temp;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1-i;j++)
{
if(x[j]>x[j+1])
{
temp=x[j];
x[j]=x[j+1];
x[j+1]=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]);
cmpsort(a,n);
for(i=0;i<n-1;i++)
printf("%d ",a[i]);
printf("%d\n",a[n-1]);
}
return 0;
}

边栏推荐
- 地球系统模式(CESM)实践技术
- Compilation method of flood control evaluation report and flood modeling under the new guidelines
- Flex layout principle and common parent elements
- Embedded sharing collection 20
- 推荐12个免费查找文献的学术网站,建议点赞、收藏!
- Getaverse, a distant bridge to Web3
- npm操作指令
- OD-Paper【1】:Rich feature hierarchies for accurate object detection and semantic segmentation
- Meta analysis [whole process, uncertainty analysis] method based on R language and meta machine learning
- DOM event flow event bubble event capture event delegate
猜你喜欢

Unity scene jump script

使用Ansible中的playbook

If MySQL calculates the current month change / current month increase / year-on-year change / year-on-year increase?

When AQS wakes up the thread, I understand why it traverses from the back to the front

Shell的read 读取控制台输入、read的使用

开发转测试:从零开始的6年自动化之路

Okaleido上线聚变Mining模式,OKA通证当下产出的唯一方式

CLM land surface process model

MySQL master-slave synchronization and master-slave synchronization delay solution

Embedded sharing collection 20
随机推荐
security权限管理详解
Okaleido上线聚变Mining模式,OKA通证当下产出的唯一方式
Date and time function of MySQL function summary
Nacos registry
517. 超级洗衣机
C语言力扣第41题之缺失的第一个正数。两种方法,预处理快排与原地哈希
OD-Paper【1】:Rich feature hierarchies for accurate object detection and semantic segmentation
Princeton calculus reader 02 Chapter 1 -- composition of functions, odd and even functions, function images
35. 搜索插入位置
地球系统模式(CESM)实践技术
元宇宙为服装设计展示提供数字化社交平台
C语言详解系列——函数的认识(3)形参,实参,嵌套调用和链式访问
Earth system model (cesm) practical technology
Teach you how to use code to realize SSO single sign on
35. Search the insertion position
no networks found in /etc/cni/net.d
SSTI-payload和各种绕过方法
Redis expiration deletion strategy and memory obsolescence strategy
Redis过期删除策略和内存淘汰策略
Unity scene jump script