Merge sort with Transylvanian saxon ( German) folk dance
void merge(int a, int low, int mid, int high) , , Variables declaration. int b new inthigh+1low; int h, i, j, k; hlow; i0; jmid+1; , , Merges the two array s into b until the first one is finish while((h mid) (j high)) if(ah aj) biah; h++; else biaj; j++; i++; , , Completes the array filling in it the missing values if(h mid) for(kj; k high; k++) biak; i++; else for(kh; k mid; k++) biak; i++; , , Prints into the original array for(k0; k highlow; k++) ak+lowbk; delete b; void mergesort(int a, int low, int high) , , Recursive sort. .. int mid; if(low high) mid(low+high), 2; mergesort(a, low, mid); mergesort(a, mid+1, high); merge(a, low, mid, high);
|