Salut à tous,
je viens vous soumettre un problème que j'ai avec un algorithme quicksort,
Je vous présente les fonctions de partition et quicksort:
j'ai l'impression que mon problème est au niveau de la fonction de partition,
Code : Sélectionner tout - Visualiser dans une fenêtre à part 
 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 int partition(int tab[], int deb, int fin) { int pivot = tab[deb]; int pos_pivot = deb; for(int i =deb+1; i <=fin; i++) { if (tab[i] < pivot) { tab[i-1]=tab[i]; tab[i]=pivot; pos_pivot++; } } return pos_pivot; } void quicksort(int tab[],int deb,int fin) { int pivot; if(deb<fin) { pivot = partition(tab,deb,fin); quicksort(tab,deb,pivot-1); quicksort(tab,pivot+1,fin); } }
pour le tableau en entrée suivant:
1165
17137
14102
11300
31285
25412
23936
254
Voici ce que j'obtiens en sortie:
1165
17137
14102
11300
31285
25412
23936
254
Je sais que des codes tout fait existent sur le net, mais j'ai vraiment envie de le faire moi même,
Merci
		
		
        



  
 


  Répondre avec citation
Partager