当前位置:网站首页>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;
}

边栏推荐
- ThreadLocal transfer between parent and child threads in asynchronous
- Mysql优化
- C语言力扣第42题之接雨水。四种方法——暴力、动态规划、栈、双指针
- LeetCode链表问题——206.反转链表(一题一文学会链表)
- ALV program collection
- NetCore MySql The user specified as a definer (‘admin‘@‘%‘) does not exist
- C language force buckle question 42 of rain. Four methods - violence, dynamic planning, stack, double pointer
- 5个chrome简单实用的日常开发功能详解,赶快解锁让你提升更多效率!
- unity场景跳转脚本
- 35. 搜索插入位置
猜你喜欢

【pytorch】torch1.8.1安装、查看torch版本、GPU是否可用

How to reproduce the official course of yolov5 gracefully (II) -- Mark and train your own data set

Common modules in ansible

security权限管理详解

ALV report flow diagram

Trend of the times - the rise of cloud native databases

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

5个chrome简单实用的日常开发功能详解,赶快解锁让你提升更多效率!

Embedded development notes, practical knowledge sharing

FPGA刷题——序列检测
随机推荐
开发转测试:从零开始的6年自动化之路
MySQL basic learning
遥感、GIS和GPS技术在水文、气象、灾害、生态、环境及卫生等领域中的应用
普林斯顿微积分读本02第一章--函数的复合、奇偶函数、函数图像
C语言详解系列——函数的认识(3)形参,实参,嵌套调用和链式访问
新人如何做好功能测试,学会这几项够用了
Bash shortcut key to improve command line efficiency [Full Version]
CLM land surface process model
Distance between bus stops: simple simulation problem
JVM Lecture 2: class loading mechanism
OD-Paper【1】:Rich feature hierarchies for accurate object detection and semantic segmentation
Nacos introduction and deployment
kubernetes install completed
SSTI-payload和各种绕过方法
Getaverse,走向Web3的远方桥梁
517. 超级洗衣机
MODFLOW Flex、GMS、FEFLOW、HYDRUS实践应用
“双碳”目标下资源环境中的可计算一般均衡(CGE)模型实践技术
SAP报表开发步骤
Shell的read 读取控制台输入、read的使用