-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbubble_sort.c
43 lines (41 loc) · 888 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
#include<stdio.h>
#include<conio.h>
void swap(int* a,int* b);
void bubblesort(int*a,int n);
void print(int * a,int n);
// main function
void main(){
int array[100];
int n;
printf("How many number is you want to enter:");
scanf("%d",&n);
printf("\n Enter value");
for(int i=0;i<n;i++){
scanf("%d",&array[i]);
}
bubblesort(array,n);
print(array,n);
printf("\n Array is sorted ");
}
void swap(int*a,int*b){
int temp;
temp=*a;
*a=*b;
*b=temp;
}
void print(int*a,int n){
printf("\n");
for(int i=0;i<n;i++){
printf("%d\t",a[i]);
}
}
void bubblesort(int*a,int n){
printf("applying sorting algorithm...\n");
for(int i=0;i<n;i++){
for(int j=0;j<n-1-i;j++){
if(a[j]>a[j+1]){
swap(&a[j],&a[j+1]);
}
}
}
}