BUBBLE SORT OPERATION IN C LANGUAGE
#include<stdio.h>
void printarray(int* A,int n){
for(int i=0;i<n;i++){
printf("%d ",A[i]);
}
printf("\n");
}
void bubblesort(int* A,int 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[]={444,6,888,5,55,66,47};
int n=7;
printarray(A,n);
bubblesort(A,n);
printarray(A,n);
return 0;
}
0 Comments