forked from fnplus/hacktoberfest-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
53 lines (47 loc) · 1.02 KB
/
main.cpp
File metadata and controls
53 lines (47 loc) · 1.02 KB
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
45
46
47
48
49
50
51
52
53
#include <iostream>
using namespace std;
void echanger(int tableau[],int a,int b)
{
int sauv = tableau[a];
tableau[a] = tableau[b];
tableau[b] = sauv;
}
int partition(int tableau[], int deb, int fin)
{
int compt=deb;
int pivot=tableau[deb];
int i;
for(i=deb+1;i<=fin;i++)
{
if(tableau[i]<pivot)
{
compt++;
echanger(tableau,compt,i);
}
}
echanger(tableau,compt,deb);
return(compt);
}
void tri_rapide_bis(int tableau[],int debut,int fin)
{
if(debut<fin)
{
int pivot=partition(tableau,debut,fin);
tri_rapide_bis(tableau,debut,pivot-1);
tri_rapide_bis(tableau,pivot+1,fin);
}
}
void tri_rapide(int tableau[],int longueur)
{
tri_rapide_bis(tableau,0,longueur-1);
}
int main()
{
int tab[10] = {10,20,10,35,40,60,12,12,30,32};
tri_rapide(tab,10);
for(int i=0;i<10;i++)
{
cout << tab[i]<<endl;
}
return 0;
}