-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubble_sort.c
More file actions
43 lines (32 loc) · 810 Bytes
/
bubble_sort.c
File metadata and controls
43 lines (32 loc) · 810 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
#include<stdio.h>
void bubble_sort(int arr[], int len);
int main()
{
int arr[] = {6, 13, 42, 5, 21, 9, 26};
int length = sizeof(arr)/sizeof(int);
bubble_sort(arr, length);
getch();
return 0;
}
void bubble_sort(int arr[], int len)
{
int i, j, temp;
for(i = 0; i < len - 1; i++)
{
for(j = 0; j < len - 1 - i; j++)
{
if(arr[j] > arr[j + 1])
{
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
printf("\nBubble sort result:");
int k;
for(k = 0; k < len; k++)
{
printf("%d ", arr[k]);
}
}