Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
58 lines (53 loc) · 1.45 KB

File metadata and controls

58 lines (53 loc) · 1.45 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<iostream>
using namespace std;
//冒泡排序
void BulleSort(int* pData, int Count)
{
// int iTemp=0;
// for(int i=1;i<Count;i++) //进行Count次排序,Count是排序的数的个数
// {
// for(int j=Count-1;j>=i;j--) //对该轮待排序的数进行排序
// {
// if(pData[j]<pData[j-1]) //将大数放在前,小数放在后
// {
// iTemp=pData[j-1];
// pData[j-1]=pData[j];
// pData[j]=iTemp;
// }
// }
// }
int temp = 0;
for(int i = 0; i<Count-1; i++){//应该排序的次数
for(int j=0; j<Count-i-1; j++){//第几次排序后就应该有几个数被排好,即不再需要比较,-i//j=1;j<Count-i;j++
if(pData[j]>pData[j+1]){//if(pData[j]<pData[j-1])
temp = pData[j];
pData[j] = pData[j+1];
pData[j+1] = temp;
}
}
}
}
//对冒泡排序进行优化
void BulleSort_Optimize(int* pData, int Count){
int i ,j ;
bool flag = true;
for(i=0;i<arrayLength-1&&flag;++i)
{
flag = false;
for(j= 1;j<arrayLength-i;++j)
if(array[j]<array[j-1])
{
Swap(array[j],array[j-1]);
flag = true; //有交换,表明当前序列尚未有序,标志为ture
}
}
}
int main()
{
int data[]={5,1,19,22,3,1,23,6}; //输入待排序数组
BulleSort(data,8); //冒泡排序法
for(int i=0;i<8;i++)
cout<<data[i]<<" ";
cout<<"\n";
return 0;
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.