Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void merge(int tab[], int p, int q, int r)
- {
- //int q = (p + r) / 2;
- int* tleft = (int*) malloc((q - p + 2)*sizeof(int));
- int* tright = (int*) malloc((r - q + 1)*sizeof(int));
- for (int i = 0; i < q - p + 1; i++)
- {
- tleft[i] = tab[p + i];
- }
- tleft[q - p + 1] = 1000;
- for (int i = 0; i < r - q; i++)
- {
- tright[i] = tab[q + i + 1];
- }
- tright[r - q] = 1000;
- int ri = 0; int le = 0;
- for (int i = p; i <= r; i++)
- {
- if (tright[ri] < tleft[le])
- {
- tab[i] = tright[ri];
- ri++;
- }
- else
- {
- tab[i] = tleft[le];
- le++;
- }
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement