-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubblesort.c
More file actions
39 lines (34 loc) · 898 Bytes
/
bubblesort.c
File metadata and controls
39 lines (34 loc) · 898 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
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include <errno.h>
void sort(int array[], int size){
for(int i=0; i<size-1; i++){
for(int j=0; j<size-i -1; j++){
if(array[j]>array[j+1]){
int temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
}
}
void printArray(int array[], int size){
for(int i=0; i<size-1; i++){
printf("%d ",array[i]);
}
}
int main() {
// Bubble sorting
int array[]={9, 1, 8, 2, 7, 3, 6, 4, 5};
int size = sizeof(array)/sizeof(array[0]);
sort(array,size);
printArray(array,size);
return 0;
}
// Bro Code. (2021.10.7.). C Programming Full Course for free [Video]. YouTube. https://www.youtube.com/watch?v=87SH2Cn0s9A