-
Notifications
You must be signed in to change notification settings - Fork 0
/
bubble_sort.c
48 lines (38 loc) · 838 Bytes
/
bubble_sort.c
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
/**
* Assignment: prelab 4
*
* @file bubble_sort.c
* @brief Algorithms: Sorting
* @author Group 1: Jennifer
* @date Sept 25, 2020
*/
#include <stdio.h>
void bubble_sort(int a[],size_t size);
int main(void)
{
int i=0;
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int b[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
int c[] = {5,7, 8, 4, 3, 10, 1, 4, 4, 5};
int size = sizeof(a) / sizeof(int);
bubble_sort(a,size);
for(i = 0; i < size; i++){
printf("Array Val: a[%d] = %d\n",i, a[i]);
}
return 0;
}
void bubble_sort(int a[],size_t size)
{
int i =0;
int tmp =0;
int sorts=0;
for(sorts=0;sorts < size -1; sorts++){
for (i=0;i < size-sorts-1; i++){
if (a[i] > a[i+1]){
tmp=a[i+1];
a[i+1]=a[i];
a[i]=tmp;
}
}
}
}