当前位置:网站首页>Select sorting and bubble sorting template
Select sorting and bubble sorting template
2022-07-04 03:38:00 【CTGU-Yoghurt】
remarks :sizeof(a)/sizeof(a[0]) The function of is to find the number of elements of the array
See this blog for more information :(1 Bar message ) About sizeof(arr)/sizeof(arr[0]) Reading (plus The detailed explanation is increased )_CTGU-Yoghurt The blog of -CSDN Blog _sizeof(arr)/sizeof(arr[0])https://blog.csdn.net/weixin_60536621/article/details/120583464?spm=1001.2014.3001.5502
Selection sort :
void xuanzhe()
{
for (int i = 0; i < sizeof(a)/sizeof(a[0])-1; i++)
{
for (int j = i+1; j < sizeof(a)/sizeof(a[0]); j++) {
if (a[i] > a[j])
{
int t = a[i];
a[i] = a[j];
a[j] = t;
}
}
}
}
Bubble sort :
void maopao()
{
for (int i = 0; i < sizeof(a) / sizeof(a[0])-1; i++)
{
for (int j = 0 ; j < sizeof(a) / sizeof(a[0])-i-1; j++) {
if (a[j] > a[j+1])
{
int t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
}
}
}
Test code :
#include<iostream>
using namespace std;
int a[] = { 123,12,312,3,124,3,4534,5,423,4};
void xuanzhe()
{
for (int i = 0; i < sizeof(a)/sizeof(a[0])-1; i++)
{
for (int j = i+1; j < sizeof(a)/sizeof(a[0]); j++) {
if (a[i] > a[j])
{
int t = a[i];
a[i] = a[j];
a[j] = t;
}
}
}
}
void maopao()
{
for (int i = 0; i < sizeof(a) / sizeof(a[0])-1; i++)
{
for (int j = 0 ; j < sizeof(a) / sizeof(a[0])-i-1; j++) {
if (a[j] > a[j+1])
{
int t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
}
}
}
int main()
{
maopao();
for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++)
{
cout << a[i]<<" ";
}
}
边栏推荐
- Consul of distributed service registration discovery and unified configuration management
- 2022 registration examination for safety production management personnel of fireworks and firecracker production units and examination skills for safety production management personnel of fireworks an
- pytest多进程/多线程执行测试用例
- Leecode 122. Zuijia timing of buying and selling stocks ②
- Mindmanager2022 efficient and easy to use office mind map MindManager
- Aperçu du code source futur - série juc
- What is cloud primordial?
- (practice C language every day) pointer sorting problem
- In my spare time, I like to write some technical blogs and read some useless books. If you want to read more of my original articles, you can follow my personal wechat official account up technology c
- Value transfer communication between components (parent to child, child to parent, brother component to value)
猜你喜欢
2022-07-03:数组里有0和1,一定要翻转一个区间,翻转:0变1,1变0。 请问翻转后可以使得1的个数最多是多少? 来自小红书。3.13笔试。
MySQL is dirty
(column 23) typical C language problem: find the minimum common multiple and maximum common divisor of two numbers. (two solutions)
Package and download 10 sets of Apple CMS templates / download the source code of Apple CMS video and film website
SQL语句加强练习(MySQL8.0为例)
MySQL maxscale realizes read-write separation
Dare to climb here, you're not far from prison, reptile reverse actual combat case
Setting methods, usage methods and common usage scenarios of environment variables in postman
What is the difference between enterprise wechat applet and wechat applet
GUI Graphical user interface programming (XIV) optionmenu - what do you want your girlfriend to wear on Valentine's day
随机推荐
Calculate the odd sum of 1~n (1~100 as an example)
[UE4] parse JSON string
MySQL is dirty
Recent learning fragmentation (14)
Summary of Chinese remainder theorem
what does ctrl + d do?
Contest3145 - the 37th game of 2021 freshman individual training match_ F: Smallest ball
2022 examination summary of quality controller - Equipment direction - general basis (quality controller) and examination questions and analysis of quality controller - Equipment direction - general b
Examination question bank of constructor decoration direction post skills (constructor) and examination data of constructor decoration direction post skills (constructor) in 2022
Which product is better for 2022 annual gold insurance?
JS object definition
Setting methods, usage methods and common usage scenarios of environment variables in postman
数据库SQL语句汇总,持续更新......
Recursive structure
How about the ratings of 2022 Spring Festival Gala in all provinces? Map analysis helps you show clearly!
System integration meets the three business needs of enterprises
MySQL query
A review of reverse reinforcement learning at Virginia Tech (VT)
Contest3145 - the 37th game of 2021 freshman individual training match_ D: Ranking
(practice C language every day) pointer sorting problem