forked from Firkraag/algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbleSort.c
More file actions
33 lines (27 loc) · 568 Bytes
/
Copy pathBubbleSort.c
File metadata and controls
33 lines (27 loc) · 568 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
//BubbleSort(A)
//for i = 1 to A.length - 1
// for j = A.length downto i + 1
// if A[j] < A[j - 1]
// swap(A[j], A[j - 1])
#include <stdio.h>
void BubbleSort(int A[], int n) {
int i, j;
for (i = 0; i < n - 1; i++)
for (j = n - 1; j > i; j--)
if (A[j] < A[j - 1]) {
int tmp = A[j];
A[j] = A[j - 1];
A[j - 1] = tmp;
}
}
int main() {
int a[1000];
int i;
for (i = 0; i < 1000; i++)
a[i] = 1000 - i;
BubbleSort(a, 1000);
for (i = 0; i < 1000; i++)
printf("%d\t", a[i]);
printf("\n");
return 0;
}