all about C++ and PHP
#include #include #include #include #include #include #include #define ARR_SIZE 15 using namespace std; void print(vector &vt) { copy(vt.begin(), vt.end(), ostream_iterator(cout, " ")); cout< &vt, int p, int r) { int mid = floor((p+r)/2); int i1 = 0; int i2 = p; int i3 = mid + 1; vector t_vt; t_vt.reserve(r-p+1); while( i2 <= mid && i3 <= r) { if ( vt[i2] < vt[i3] ) t_vt[i1++] = vt[i2++]; else t_vt[i1++] = vt[i3++]; } while (i2 <= mid ) t_vt[i1++] = vt[i2++]; while ( i3 <= r ) t_vt[i1++] = vt[i3++]; for(int i = p; i <= r; i++) vt[i] = t_vt[i-p]; } /*Algorithm 1> Split the list into two equal parts at the middle 2> Apply merge_sort() on each list 3> Merge both the lists */ void merge_sort(vector &vt, int p, int r) { if(p vt; vt.reserve(ARR_SIZE); srand(time(NULL)); for(int i=0; i
Unsorted : 308 259 354 738 444 7 891 756 63 56 460 961 732 38 648 Sorted : 7 38 56 63 259 308 354 444 460 648 732 738 756 891 961
No comments:
Post a Comment