Category : mergesort

I have built functions related to quick sort and merge sort. I am not getting any errors but still I am not getting the required output. #include <iostream> using namespace std; void swap(int *a, int *b); void printarray(int array[], int size); int partition(int array[], int low, int high, int select); void quicksort(int array[], int low, ..

Read more

I have learned Merge Sort algorithm in C++ recently and have come across 2 different ways by which it is implemented in tutorials. 1st way: void merge(int arr[],int low,int mid,int high){ const int n1=(mid-low+1); const int n2=(high-mid); int*a=new int[n1],*b=new int[n2];//dynamically allocated because of MSVC compiler for(int i=0;i<n1;i++) a[i]=arr[low+i]; for(int i=0;i<n2;i++) b[i]=arr[mid+1+i]; int i=0,j=0,k=low; while(i<n1 && ..

Read more