Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. int tab[10]={3,2,7,8,5,6,9,7,2,4};
  3.  
  4. void echange (int i, int j){
  5. int tmp = tab [i];
  6. tab [i]=tab [j];
  7. tab [j]=tmp;
  8. }
  9. void fct (int gauche, int droit){
  10. int i, dernier;
  11. if(gauche>=droit)
  12. return;
  13. echange(gauche, (gauche+droit)/2);
  14. dernier=gauche;
  15. for(i=gauche+1;i<=droit;i++){//Here begins to order the vector
  16. if (tab[i]<tab[gauche])
  17. echange(++dernier,i);
  18. }
  19. echange (gauche,dernier);//In these lines I get confused.
  20. fct(gauche,dernier-1); //What do you intend to do here?
  21. fct(dernier+1,droit);
  22. }
  23. int main()
  24. {
  25. int i;
  26. fct(0,9);
  27.  
  28. for(i=0;i<10;i++){
  29. printf("%d_",tab[i]);
  30. }
  31.  
  32. return 0;
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement