fork(1) download
  1. program trirapide;
  2. uses crt;
  3.  
  4. type
  5. tab = array [1..100] of integer;
  6.  
  7. var
  8. t : tab;
  9. n : integer;
  10.  
  11. procedure remplissage (var t : tab ; var n : integer );
  12. var
  13. i:integer ;
  14. begin
  15. repeat
  16. writeln ('donner le taille de tableau ');
  17. readln(n);
  18. until (n > 0) and (n <= 100);
  19. for i := 1 to n do
  20. begin
  21. writeln ('t[',i,']');
  22. readln(t[i]);
  23. end;
  24. end ;
  25.  
  26. procedure tri_rapid (var t : tab ; pivot : integer ; n : integer);
  27. var
  28. aux, sup, inf : integer;
  29. begin
  30. if n - pivot > 0 then
  31. begin
  32. inf := pivot + 1;
  33. sup := n;
  34. repeat
  35. while (inf < sup) and (t[pivot] > t[inf]) do
  36. inf := inf + 1;
  37. while (inf <= sup) and (t[pivot] <= t[sup]) do
  38. sup := sup - 1;
  39. if (inf < sup) then
  40. begin
  41. aux := t[inf];
  42. t[inf] := t[sup];
  43. t[sup] := aux;
  44. end;
  45. until (sup<inf);
  46. aux := t[pivot];
  47. t[pivot] := t[sup];
  48. t[sup] := aux;
  49. tri_rapid (t, pivot, sup-1);
  50. tri_rapid (t, sup+1, n);
  51. end;
  52. end;
  53.  
  54. procedure affichage (t : tab ; n : integer);
  55. var
  56. i : integer;
  57. begin
  58. for i := 1 to n do
  59. writeln(t[i]);
  60. end;
  61.  
  62. begin
  63. remplissage (t, n);
  64. tri_rapid (t, 1, n);
  65. affichage (t, n);
  66. end.
  67.  
Success #stdin #stdout 0s 272KB
stdin
5
32
4
76
12
23
stdout
donner le taille de tableau 
t[1]
t[2]
t[3]
t[4]
t[5]
4
12
23
32
76