-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuicksort.cpp
44 lines (36 loc) · 978 Bytes
/
Quicksort.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
using namespace std;
void Quicksort(int* arr, int izq, int der)
{
int i = izq, j = der, tmp;
int p = arr[(izq + der) / 2];
while (i <= j)
{
while (arr[i] < p) i++;
while (arr[j] > p) j--;
if (i <= j)
{
tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
i++; j--;
}
}
if (izq < j)
Quicksort(arr, izq, j);
if (i < der)
Quicksort(arr, i, der);
}
int main()
{
cout<< "Este es el Metodo QuickSort\n\n";
cout<< "Esta es la lista a ordenar\n";
cout<< "88, 6, 69, -33, 98, 7, 23, 5, 0, 100\n\n";
cout<< "La lista de abajo ya se ha ordenado:\n\n";
int arreglo[10] = { 88, 6, 69, -33, 98, 7, 23, 5, 0, 100};
Quicksort(arreglo, 0, 9);
for(int i = 0; i < 10; i++)
cout << arreglo[i] << " ";
system("pause");
return 0;
}