All Sort
All Sort
All Sort
#include <iostream>
#include <vector>
#include<bits/stdc++.h>
int pos,i;
int x;
for (i = 1; i<n;i++)
x = a[i];
pos = i -1;
a[pos + 1] =a[pos];
pos--;
a[pos+1] = x;
int main()
double s, e , t;
s = clock();
int n;
cin>> n;
ifstream exam;
exam.open("a.txt");
exam.close();
Insertion(a,n);
e = clock();
t = (e - s)/CLOCKS_PER_SEC;
cout<<"time: "<< t;
return 0;
QUICK SORT
#include <iostream>
#include<bits/stdc++.h>
int temp = a;
a = b;
b = temp;
int i, j , x;
x = a[(left + right)/2];
i = left;
j = right;
while (i < j)
i++;
j--;
if(i<= j)
hoanvi(a[i], a[j]);
i++;
j--;
if (left<j)
if (i < right )
int main()
double s,e,t;
s = clock();
int n;
cin>> n;
ifstream exam ;
exam.open ("a.txt");
Quicksort(a,0, n -1);
e = clock();
t = (e - s)/CLOCKS_PER_SEC;
cout<<"Time: "<< t;
return 0;
HEAP SORT
#include <stdio.h>
#include<bits/stdc++.h>
*a = *b;
*b = temp;
int largest = i;
int left = 2 * i + 1;
int right = 2 * i + 2;
largest = left;
largest = right;
if (largest != i) {
swap(&arr[i], &arr[largest]);
heapify(arr, N, largest);
}}
heapify(arr, N, i);
swap(&arr[0], &arr[i]);
heapify(arr, i, 0);}
int main()
double s,e,t;
s = clock();
int n;
cin>> n;
ifstream exam;
exam.open("a.txt");
exam.close();
heapSort(arr, N);
e = clock();
t = (e - s)/CLOCKS_PER_SEC;
cout<<"Time: "<< t;
return 0;
}
MERGE SORT
#include <iostream>
#include<bits/stdc++.h>
int right)
int o = 0;
int p = 0;
int k= left;
if (a[o]<= b[p]) {
array[k]= a[o];
o++;
else {
array[k]= b[p];
p++;
}
k++;
while (o < x) {
array[k]= a[o];
o++;
k++;
while (p < y) {
array[k]= b[p];
p++;
k++;
delete[] a;
delete[] b;
if (beg>= en)
return;
int main()
double s,e,t;
s = clock();
int n;
cin>> n;
ifstream exam;
exam.open("a.txt");
exam.close;
mergeSort(a,0, n -1);
e = clock();
t = (e - s)/CLOCKS_PER_SEC;
cout<<"Time: "<< t;
return 0;