diff --git a/Problems and General Algos/sorting_algos.cpp b/Problems and General Algos/sorting_algos.cpp new file mode 100644 index 0000000..abc4bde --- /dev/null +++ b/Problems and General Algos/sorting_algos.cpp @@ -0,0 +1,98 @@ +#include +using namespace std; + +void swap(int *x,int* y){ + int temp; + temp=*x; + *x=*y; + *y=temp; +} + +void insertion_sort(int a[],int n){ + int i,j,x; + for(i=1;i-1 && a[j]>x){ + a[j+1]=a[j]; + j--; + } + a[j+1] = x; + + } +} + +void selection_sort(int a[],int n){ + int i,j,k; + for(i=0;i=1;gap/=2){ + for(i=gap;i0 && a[j]>temp){ + a[j+gap] = a[j]; + j=j-gap; + + } + a[j+gap] = temp; + } + } +} +int main(){ + int a[] = {2,4,1,8,5,28,18,6}; + int n= sizeof(a)/sizeof(a[0]); + int i; + // selection_sort(a,n); + // IMergesort(a,n); + shellsort(a,n); + for(i=1;i