- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
void Merging_Sort (int n, int *x){
int i, j, k, t, s, Fin1, Fin2;
int* tmp = new int[n];
k = 1;
while (k < n){
t = 0; s = 0;
while (t+k < n){
Fin1 = t+k;
Fin2 = (t+2*k < n ? t+2*k : n);
i = t; j = Fin1;
for ( ; i < Fin1 && j < Fin2 ; s++){
if (x[i] < x[j]) {
tmp[s] = x[i]; i++;
} else {
tmp[s] = x[j]; j++;
}
}
for ( ; i < Fin1; i++, s++) tmp[s] = x[i];
for ( ; j < Fin2; j++, s++) tmp[s] = x[j];
t = Fin2;
} k *= 2;
for (s = 0; s < t; s++) x[s] = tmp[s];
}
delete(tmp);
}
Ksyrx 29.07.2019 05:56 # 0