当前位置:网站首页>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]<<" ";
}
}
边栏推荐
- The difference between MCU serial communication and parallel communication and the understanding of UART
- Add token validation in swagger
- 機器學習基礎:用 Lasso 做特征選擇
- [untitled]
- Mindmanager2022 efficient and easy to use office mind map MindManager
- What is cloud primordial?
- 用于TCP协议交互的TCPClientDemo
- MySQL query
- The 37 year old programmer was laid off, and he didn't find a job for 120 days. He had no choice but to go to a small company. As a result, he was confused
- Contest3145 - the 37th game of 2021 freshman individual training match_ 1: Origami
猜你喜欢
Jenkins continuous integration environment construction V (Jenkins common construction triggers)
What are the virtual machine software? What are their respective functions?
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
If you have just joined a new company, don't be fired because of your mistakes
渗透实战-SQLServer提权
What is the difference between enterprise wechat applet and wechat applet
New year's first race, submit bug reward more!
微信公众号网页授权
Session learning diary 1
ctf-pikachu-CSRF
随机推荐
Don't disagree, this is the most powerful "language" of the Internet
2022 examination summary of quality controller - Equipment direction - general basis (quality controller) and examination questions and analysis of quality controller - Equipment direction - general b
Contest3145 - the 37th game of 2021 freshman individual training match_ G: Score
Résumé des outils communs et des points techniques de l'examen PMP
Zhihu million hot discussion: why can we only rely on job hopping for salary increase? Bosses would rather hire outsiders with a high salary than get a raise?
Aperçu du code source futur - série juc
Add token validation in swagger
Contest3145 - the 37th game of 2021 freshman individual training match_ F: Smallest ball
1289_FreeRTOS中vTaskSuspend()接口实现分析
智慧地铁| 云计算为城市地铁交通注入智慧
Leecode 122. Zuijia timing of buying and selling stocks ②
Development of digital collection trading platform development of digital collection platform
Enhanced for loop
ctf-pikachu-CSRF
Package and download 10 sets of Apple CMS templates / download the source code of Apple CMS video and film website
[database I] database overview, common commands, view the table structure of 'demo data', simple query, condition query, sorting data, data processing function (single row processing function), groupi
2022-07-03:数组里有0和1,一定要翻转一个区间,翻转:0变1,1变0。 请问翻转后可以使得1的个数最多是多少? 来自小红书。3.13笔试。
Tsinghua University product: penalty gradient norm improves generalization of deep learning model
[Wu Enda deep learning] beginner learning record 3 (regularization / error reduction)
[PaddleSeg 源码阅读] PaddleSeg 自定义数据类