当前位置:网站首页>选择排序与冒泡排序模板
选择排序与冒泡排序模板
2022-07-04 03:32:00 【CTGU-Yoghurt】
备注:sizeof(a)/sizeof(a[0])的作用为求数组的元素个数
选择排序:
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;
}
}
}
}测试代码:
#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]<<" ";
}
}边栏推荐
- Solve the problem that the tabbar navigation at the bottom of vantui does not correspond to the page (window.loading.hash)
- Handler source code analysis
- XSS prevention
- Fudan released its first review paper on the construction and application of multimodal knowledge atlas, comprehensively describing the existing mmkg technology system and progress
- How about the ratings of 2022 Spring Festival Gala in all provinces? Map analysis helps you show clearly!
- Which product is better for 2022 annual gold insurance?
- Pagoda SSL can't be accessed? 443 port occupied? resolvent
- Basé sur... Netcore Development blog Project Starblog - (14) Implementation of theme switching function
- Setting methods, usage methods and common usage scenarios of environment variables in postman
- 2022 examination summary of quality controller - Equipment direction - general basis (quality controller) and examination questions and analysis of quality controller - Equipment direction - general b
猜你喜欢

Package details_ Four access control characters_ Two details of protected

Rhcsa day 3

Hospital network planning and design document based on GLBP protocol + application form + task statement + opening report + interim examination + literature review + PPT + weekly progress + network to

GUI Graphical user interface programming (XIV) optionmenu - what do you want your girlfriend to wear on Valentine's day

Redis transaction

Setting methods, usage methods and common usage scenarios of environment variables in postman

Constantly changing harmonyos custom JS components during the Spring Festival - Smart Koi

Jenkins configures IP address access

Zblog collection plug-in does not need authorization to stay away from the cracked version of zblog

The difference between MCU serial communication and parallel communication and the understanding of UART
随机推荐
Johnson–Lindenstrauss Lemma
Fudan released its first review paper on the construction and application of multimodal knowledge atlas, comprehensively describing the existing mmkg technology system and progress
How to use STR function of C language
How about the ratings of 2022 Spring Festival Gala in all provinces? Map analysis helps you show clearly!
Session learning diary 1
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
PID of sunflower classic
Dare to climb here, you're not far from prison, reptile reverse actual combat case
WordPress collection WordPress hang up collection plug-in
[UE4] parse JSON string
Want to do something in production? Then try these redis commands
Recent learning fragmentation (14)
Add IDM to Google browser
Talking about custom conditions and handling errors in MySQL Foundation
What is the difference between enterprise wechat applet and wechat applet
Formulaire day05
Webhook triggers Jenkins for sonar detection
Baijia forum the founding of the Eastern Han Dynasty
The difference between MCU serial communication and parallel communication and the understanding of UART
(column 23) typical C language problem: find the minimum common multiple and maximum common divisor of two numbers. (two solutions)
https://blog.csdn.net/weixin_60536621/article/details/120583464?spm=1001.2014.3001.5502