diff --git a/bubble_sort b/bubble_sort index 0f57f61..1fb4b1e 100644 --- a/bubble_sort +++ b/bubble_sort @@ -1,36 +1,31 @@ - -#include -#define MAX 100 -int main(void) +#include + +using namespace std; + +int main() { - int arr[MAX],i,j,temp,n,xchanges; - printf("Enter the number of elements : "); - scanf("%d",&n); - for(i=0; i>n; + cout<<"Enter the array elements: "; + + for(i=0;i>a[i]; + + for(i=1;i arr[j+1]) + for(j=0;j<(n-i);++j) + if(a[j]>a[j+1]) { - temp = arr[j]; - arr[j] = arr[j+1]; - arr[j+1] = temp; - xchanges++; + temp=a[j]; + a[j]=a[j+1]; + a[j+1]=temp; } - } - if(xchanges==0) /*If list is sorted*/ - break; } - printf("Sorted list is :\n"); - for(i=0; i -#define MAX 100 -int main(void) +#include + +using namespace std; + +int main() { - int arr[MAX],i,j,k,n; - printf("Enter the number of elements : "); - scanf("%d",&n); - for(i=0; i=0 && k>n; + cout<<"\nEnter the elements\n"; + + for(i=0;i>a[i]; + } + + for(i=0;ia[j]) + { + min=a[j]; + loc=j; + } + } + + temp=a[i]; + a[i]=a[loc]; + a[loc]=temp; + } + + cout<<"\nSorted list is as follows\n"; + for(i=0;i