-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path51_bubble_sort.c
More file actions
39 lines (37 loc) · 855 Bytes
/
Copy path51_bubble_sort.c
File metadata and controls
39 lines (37 loc) · 855 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>
void print(int *A,int n){
for(int i=0;i<n;i++){
printf("%d ",A[i]);
}
printf("\n");
}
void bubblesort(int *A,int n){
printf("Sorted array using Bubble Sort:\n");
int temp;
int issorted = 0;
for(int i = 0;i<n-1;i++){
printf("Working on pass number %d\n",i+1);
issorted = 1;
for (int j = 0; j < n - 1 - i; j++){
if(A[j]>A[j+1]){
temp = A[j];
A[j]=A[j+1];
A[j+1] = temp;
issorted = 0;
}
if(issorted){
return ;
}
}
}
}
int main(){
int A[] = {54,9,1,7,3,416,653};
// int A[]={1,2,3,4,5,6,};
int n = sizeof(A)/sizeof(A[0]);
printf("original Array");
print(A,n);
bubblesort(A,n);
print(A,n);
return 0;
}