Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ** sort.cpp for Elendil in /home/viller_m/Desktop/
- **
- ** Made by mickael villers
- ** Login <[email protected]>
- **
- ** Started on Thu Apr 16 22:04:07 2015 mickael villers
- ** Last update Thu Apr 16 22:28:59 2015 mickael villers
- */
- #include <iostream>
- using namespace std;
- const int N = 10;
- void echanger(int &a, int &b)
- {
- int tmp;
- tmp = a;
- a = b;
- b = tmp;
- }
- int partitionner(int *tableau, int debut, int fin, int pivot)
- {
- int i;
- int j;
- i = debut - 1;
- j = fin + 1;
- while (1) {
- do{
- j--;
- } while (tableau[j] > pivot);
- do{
- i++;
- } while (tableau[i] < pivot);
- if (i < j) {
- echanger(tableau[i], tableau[j]);
- }
- else {
- return j;
- }
- }
- }
- void triRapide(int *tableau, int debut, int fin)
- {
- int pivot;
- if (debut < fin) {
- pivot = partitionner(tableau, debut, fin, tableau[debut]);
- triRapide(tableau, debut, pivot);
- triRapide(tableau, pivot+1, fin);
- }
- }
- int main(int argc, char **argv)
- {
- int tableau[N] = {16, 2, 77, 40, 1, 12, 23, 33, 76, 7};
- triRapide(tableau, 0, N - 1);
- for (int i = 0; i < N; i++)
- {
- cout << tableau[i];
- if (i < N - 1) {
- cout << ", ";
- }
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement