-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubble Sort
More file actions
47 lines (46 loc) · 947 Bytes
/
Copy pathBubble Sort
File metadata and controls
47 lines (46 loc) · 947 Bytes
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
#include <stdio.h>
#define N 1024
int main ()
{
printf("hello world!\n");
int row = 0;
int column = 0;
int array[N][N] = {};
printf("请输入一个二维数组:\n");
printf("请输入数组行数:\n");
scanf("%d",&row);
printf("请输入数组列数:\n");
scanf("%d",&column);
for(int i = 0;i<row;i++)
{
printf("请输入第%d行:\n",i+1);
gets("%s",&array[i][]);
}
int a[][] = array[row][column];
//bubble sort
for(int i = 0;i<row;i++)
{//row
for(int j = 0;j<column-1;j++)
{//column
for(int k = i;column-1-j;k++)
{//each time to compare
int temp = 0;
//exchange
if(a[i][j]<a[i][j+1])
{
temp = a[i][j];
a[i][j] = a[i][j+1];
a[i][j+1] = temp;
}
}
}
}
printf("降序冒泡排列结果为:\n");
for(int i = 0;i<row;i++)
{
puts(a[i][]);
printf("\n");
}
return 0;
//end
}