当前位置:网站首页>选择排序与冒泡排序模板
选择排序与冒泡排序模板
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)
- 96% of the collected traffic is prevented by bubble mart of cloud hosting
- Li Chuang EDA learning notes IX: layers
- The property of judging odd or even numbers about XOR.
- Management and thesis of job management system based on SSM
- 1day vulnerability pushback skills practice (3)
- Examination question bank of constructor decoration direction post skills (constructor) and examination data of constructor decoration direction post skills (constructor) in 2022
- CSCI 2134
- 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
- WP collection plug-in free WordPress collection hang up plug-in
猜你喜欢

What is cloud primordial?

PHP database connection succeeded, but data cannot be inserted

Webhook triggers Jenkins for sonar detection

What are the conditions for the opening of Tiktok live broadcast preview?

150 ppt! The most complete "fair perception machine learning and data mining" tutorial, Dr. AIST Toshihiro kamishima, Japan

Recursive structure

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

WordPress collection WordPress hang up collection plug-in

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

Is it really so difficult to learn redis? Today, a fan will share his personal learning materials!
随机推荐
How about the ratings of 2022 Spring Festival Gala in all provinces? Map analysis helps you show clearly!
Constantly changing harmonyos custom JS components during the Spring Festival - Smart Koi
Recent learning fragmentation (14)
Have you entered the workplace since the first 00???
Aperçu du code source futur - série juc
[Valentine's Day confession code] - Valentine's Day is approaching, and more than 10 romantic love effects are given to the one you love
@Scheduled scheduled tasks
Love and self-discipline and strive to live a core life
Experience summary of the 12th Blue Bridge Cup (written for the first time)
PMP 考試常見工具與技術點總結
(practice C language every day) pointer sorting problem
Teach you how to optimize SQL
Slurm view node configuration information
Which product is better if you want to go abroad to insure Xinguan?
Bugku Zhi, you have to stop him
Optimization theory: definition of convex function + generalized convex function
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
[development team follows] API specification
Stm32bug [the project references devices, files or libraries that are not installed appear in keilmdk]
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
https://blog.csdn.net/weixin_60536621/article/details/120583464?spm=1001.2014.3001.5502