Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
MergeSort
//g++ 7.4.0 //Merge sort //merge sort code credit to javaTpoint //template modifications and test driver code created by Rezaul Hoque on April 06,2021 //please contact at jewelmrh@yahoo.com #include<iostream> using namespace std; template <class T> void mergeSort(T[],int,int); template <class T> void merge(T[],int,int,int); template <class T> void mergeSort(T a[], int start, int fin) { int mid; if(start < fin) { mid = (start +fin)/2; mergeSort(a,start,mid); mergeSort(a,mid+1,fin); merge(a,start,mid,fin); } } template <class T> void merge(T a[], int start, int mid, int fin) { int i=start,j=mid+1,k,index = start; T temp[10]; while(i<=mid && j<=fin) { if(a[i]<a[j]) { temp[index] = a[i]; i = i+1; } else { temp[index] = a[j]; j = j+1; } index++; } if(i>mid) { while(j<=fin) { temp[index] = a[j]; index++; j++; } } else { while(i<=mid) { temp[index] = a[i]; index++; i++; } } k = start; while(k<index) { a[k]=temp[k]; k++; } } int main () { int a[10]= {101,123,124,6,5,90,76,67,45,65}; char c[10]={'k','n','z','y','t','d','s','g','p','q'}; int i; mergeSort(a,0,9); cout<<"After merge sort:\n"; for(i=0;i<10;i++) { cout<<" "<<a[i]; } cout<<endl; mergeSort(c,0,9); for(i=0;i<10;i++) { cout<<" "<<c[i]; } return 0; }
run
|
edit
|
history
|
help
0
KMP substring search
GenericPacker
Wipro Problem 2: determine count
Coin changes
Vector impl
TempSpecial2
Boost phoenix. e.g 2: functor
CharSearch
HashO
Ternary operator - warnings about unsued values