1 Auditoire 1ère Année CPI Année Universitaire 2020-2021 TD Algorithmique, stru
1 Auditoire 1ère Année CPI Année Universitaire 2020-2021 TD Algorithmique, structure des données et complexité Corrigé Série d’exercices N°3 Les Piles Enseignante responsable : Olfa JEMAI Exercice 1 : /* pour identifier tous les chiffres qui composent un nombre, on procède par des divisions successives par 10 Exemple : 2345 10 5 234 10 4 23 10 3 2 10 2 0 */ Type pile : pointeur sur elm-pile Procédure Affichage( nb:entier) Var P : pile y, s, z :entier Début Creerpile(P) y nb Tantque (y ≠ 0) faire s y mod 10 empiler (P,s) y y div 10 fin tantque Tantque (non pilevide(P)) faire depiler (P,z) ecrire(z) fin tantque Fin 5 4 3 2 P 2 Exercice 2 : Procédure Parité(P1 :pile, var P2:pile var P3 :pile) Var x :entier Début creerpile(P2) creerpile(P3) tantque (P1 ≠ null) faire depiler(P1,x) si (x mod 2 = 0) alors empiler(P2,x) sinon empiler(P3,x) finsi fin tantque Fin Exercice 3 : 1- Procédure prefixe(exp_par : chaine, var exp_pref :chaine) Var i :entier P :pile x :caractère Début Exp_pref’’ Creerpile(P) pour i de long(exp_par) à 1 par pas -1 faire si (operateur(exp_par[i])=faux ) alors concat(exp_par[i],exp_pref) sinon si (operateur(exp_par[i])=vrai ) alors empiler(P, exp_par[i]) sinon si exp_par[i]=’(‘ alors concat(sommetpile(P),exp_pref) depiler(P,x) 3 finsi finsi finsi fin pour Fin 2- Fonction eval_pref(exp_pref : chaine ) :réel Var P : pile i : entier opr1,opr2 :entier r :réel Début creerpile(P) pour i de long(exp_pref) à 1 par pas -1 faire si (operateur(exp_pref[i])=faux ) alors empiler(P, exp_pref[i]) sinon si binaire(exp_pref[i]) alors depiler(P,opr1) depiler(P,opr2) roperationb(opr1,exp_pref[i],opr2) empiler(P, r) sinon depiler(P,opr1) roperationu(opr1,exp_pref[i]) empiler(P, r) finsi finsi fin pour eval_pref sommetpile(P) fin 2-expression préfixée : ^ > + + A B D H < E F uploads/s1/ corrige-td3-piles 1 .pdf
Documents similaires
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/AH25YA6EUBofBo4DRW1fJnoEan5a7ZoqGm7Wk5GWAWt4RCk81jwIbpY9KmY3E5WjNywKELYTnUlz1yN57WEEJR1e.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/4gZODz3R7eZo4IPBgdPRVx2pUVXhMeSql5YfIkOli7Ink1y18ygYfP6lxRh3ahNsLsFWYMBxZgjuATg6mnsIVykO.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/007OnP4JfwRsan8uoQem9uEjyDOHdDdrM5h4EbTfUgbmWh00HmYUOKN7BoeqHbXZGdVFlnI3EZ2IRRb2aD1jBnZQ.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/jt3lL1agkJAbXHKHN3SeFloEXPfGNreVdEN4P97fwzbhbVlCjpiuMB4CNB1jJcATgIyec6vGzhjBS5xj0pZFsS0r.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/N4vvrsBVUPK4GT4eMFvq8ynGSqznVHsanP2LincBiyJPALM4XlcdBoDXT4rZGa1jKyY0vcbV7Rc6vmMipnoRUxIB.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/8v1zgJjrveJjm1V1vxxFyZOEQu2z1CiCrvn3nXpKflsnWApeNUuSNSDb32Spi8UNhbZRaNZmNuaEP3bQlkOLgigD.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/ZsRKklxAwzYBm4qNGP3i8YYpB8CJHp6ftkY8v6OeCSS6L2yJN15cQ8RBavvSUpYxXgdf7ub1SdfW5K5eGl9mZXUC.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/ddP3WUejAy0RRVLrMwuAKXSVGCIXY8SiHnA80sDeHx9hVJ27oHbtSCdpdXzTz8mMzXVRgWY3PfkQlaoPQw6qxjSO.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/aHOKoMVtfcM6vak0mFcRlZ7CZQXd5tF1vR1SWOgWHqcFaigEb2kEnf6dbaUw3HdlOxUZa1mStYMR35ERMqHqAKgo.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/F1kZLT148oAFnNHaBPTuddBdKK8fCx6MWYXB0AZgMH4ZELEo5EDEzWy9awg3lbdLXvQkwj7nUm1K5G0qAqsguUs5.png)
-
26
-
0
-
0
Licence et utilisation
Gratuit pour un usage personnel Attribution requise- Détails
- Publié le Dec 27, 2021
- Catégorie Administration
- Langue French
- Taille du fichier 0.1708MB