From 5a9d67206aee9ebe893e9695f5995621c3eeef66 Mon Sep 17 00:00:00 2001 From: abhishekg29 <56039127+abhishekg29@users.noreply.github.com> Date: Tue, 1 Oct 2019 22:06:05 +0530 Subject: [PATCH 1/3] Update bubble_sort --- bubble_sort | 53 ++++++++++++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 29 deletions(-) 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 Date: Tue, 1 Oct 2019 22:32:59 +0530 Subject: [PATCH 2/3] Update selection_sort --- selection_sort | 67 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/selection_sort b/selection_sort index 15bc93e..c9dd9a1 100644 --- a/selection_sort +++ b/selection_sort @@ -1,27 +1,42 @@ - -#include -#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 Date: Tue, 1 Oct 2019 22:35:16 +0530 Subject: [PATCH 3/3] Update selection_sort