当前位置:网站首页>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]<<" ";
}
}边栏推荐
- SQL statement strengthening exercise (MySQL 8.0 as an example)
- Recent learning fragmentation (14)
- (practice C language every day) pointer sorting problem
- Recursive structure
- No clue about the data analysis report? After reading this introduction of smartbi, you will understand!
- 基于PHP的轻量企业销售管理系统
- Which product is better if you want to go abroad to insure Xinguan?
- [development team follows] API specification
- Calculate the odd sum of 1~n (1~100 as an example)
- MySQL backup notes
猜你喜欢

Add IDM to Google browser
![[latex] production of complex tables: excel2latex and detail adjustment](/img/39/0d448ddf006eda262de3ed75666354.jpg)
[latex] production of complex tables: excel2latex and detail adjustment

What are the virtual machine software? What are their respective functions?

If you have just joined a new company, don't be fired because of your mistakes

JSON string conversion in unity

logistic regression

Cache general management class + cache httpcontext Current. Cache and httpruntime Differences between caches

Teach you how to optimize SQL

JVM family -- monitoring tools
![Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]](/img/ad/b675364fcaf5d874397fd0cbfec11b.jpg)
Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]
随机推荐
National standard gb28181 protocol platform easygbs fails to start after replacing MySQL database. How to deal with it?
ctf-pikachu-CSRF
Sword finger offer:55 - I. depth of binary tree
How to pipe several commands in Go?
Jenkins configures IP address access
“软硬皆施”,助力建成新型云计算数据中心
Résumé des outils communs et des points techniques de l'examen PMP
Katalon框架测试web(二十六)自动发邮件
[PaddleSeg 源码阅读] PaddleSeg 自定义数据类
Constantly changing harmonyos custom JS components during the Spring Festival - Smart Koi
System integration meets the three business needs of enterprises
2022 attached lifting scaffold worker (special type of construction work) free test questions and attached lifting scaffold worker (special type of construction work) examination papers 2022 attached
Audio and video technology development weekly | 232
Aperçu du code source futur - série juc
[UE4] parse JSON string
Development of digital collection trading platform development of digital collection platform
How much does it cost to open a futures account in China? Where is it safe to open an account at present?
Contest3145 - the 37th game of 2021 freshman individual training match_ G: Score
Examination question bank of constructor decoration direction post skills (constructor) and examination data of constructor decoration direction post skills (constructor) in 2022
system information