template class sorting arr long first long last new arr last first fir

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
template <class T> T sorting(T[] arr, long first, long last) {
T *p = new arr[(last - first)/2 + first];
T temp;
long i = first, j = last;
while(i <= j) {
while(arr[i] < p && i <= last) ++i;
while(arr[j] > p && j >= first) --j;
if(i <= j) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
++i; --j;
}
}
if(j > first) sorting(arr, first, j);
if(i < last) sorting(arr, i, last);
return 0;
}