Skip to content

Commit bf3979a

Browse files
authored
冒泡排序
1 parent 94ae8b2 commit bf3979a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Bubble-Sort.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <cstdio>
2+
#include <cstdlib>
3+
4+
using namespace std;
5+
6+
int data[1000];
7+
8+
void bubble_sort(int *d, int n)
9+
{
10+
for (int k = 1; k < n; k++)
11+
{
12+
for (int i = 1; i < n; i++)
13+
{
14+
if (d[i] < d[i - 1])
15+
{
16+
int temp = d[i];
17+
d[i] = d[i - 1];
18+
d[i - 1] = temp;
19+
}
20+
}
21+
}
22+
}
23+
24+
int main()
25+
{
26+
for (int i = 0; i < 1000; i++)
27+
{
28+
data[i] = rand();
29+
}
30+
31+
bubble_sort(data, 1000);
32+
33+
for (int i = 0; i < 1000; i++)
34+
{
35+
printf("%d\n", data[i]);
36+
}
37+
38+
return 0;
39+
}

0 commit comments

Comments
 (0)