-{int n = MAX-1;
- int i, g, d, x;
- TAS t;
-
- srand(time(NULL));
- for (i=1;i<=n;i++) t[i] = rand()%MAX;
- affiche_tas(t,n,"Le tableau initial");
-
- g = (n / 2) + 1; d = n;
- while (g > 1) descente(t,--g,d);
-
- affiche_tas(t,n,"Apres contruction du tas");
- change(t, 45, 7, 10);
- affiche_tas(t,n,"Le tas apres change(t,45,7,10)");
- change(t, -5, 3, 10);
- affiche_tas(t,n,"Le tas apres change(t,-5,3,10)");
-
- while (d > 1) {
- x=t[1]; /* le max */
- t[1]=t[d]; /* le dernier devient le premier du tableau */
- t[d]=x; /* le max est place a la fin du tableau */
- descente(t,g,--d); /* on fait descendre le nouveau premier elt a sa bonne place */
- }
- affiche_tas(t,n,"Le tas apres le tri");
-
- for (i=1;i<n;i++) if (t[i]>t[i+1]) {printf("Erreur tri\n");break;}
-}
-
+{
+ int n = MAX - 1;
+ int i, g, d, x;
+ TAS t;
+
+ srand(time(NULL));
+ for (i = 1; i <= n; i++)
+ t[i] = rand() % MAX;
+ affiche_tas(t, n, "Le tableau initial");
+
+ g = (n / 2) + 1;
+ d = n;
+ while (g > 1)
+ descente(t, --g, d);
+
+ affiche_tas(t, n, "Apres contruction du tas");
+ change(t, 45, 7, 10);
+ affiche_tas(t, n, "Le tas apres change(t,45,7,10)");
+ change(t, -5, 3, 10);
+ affiche_tas(t, n, "Le tas apres change(t,-5,3,10)");
+
+ while (d > 1) {
+ x = t[1]; /* le max */
+ t[1] = t[d]; /* le dernier devient le premier du tableau */
+ t[d] = x; /* le max est place a la fin du tableau */
+ descente(t, g, --d); /* on fait descendre le nouveau premier elt a sa bonne place */
+ }
+ affiche_tas(t, n, "Le tas apres le tri");
+
+ for (i = 1; i < n; i++)
+ if (t[i] > t[i + 1]) {
+ printf("Erreur tri\n");
+ break;
+ }
+}