#include <iostream> #include <stack> using namespace std; template<class T, class C> void afficher_stack(stack<T, C>& qStack); int main() { // Création d'un stack de int stack<int> intStack; cout << "nLe stack 'intStack' crée:n"; /* Afficher les propriétés de stack crée*/ afficher_stack(intStack); /* Ajout des éléments dans le stack */ for (unsigned int i = 0; i < 10; ++i) intStack.push(i * 2); /* Afficher les propriétés de stack*/ cout << "Après Ajout, intStack:n"; afficher_stack(intStack); /* Modifier l'élément qui est à la tête du stack*/ intStack.top() = 80; cout << "Après la modification, intStack:n"; afficher_stack(intStack); /* Afficher les élément du stack*/ cout << "Les contenu de l'adaptateur 'satck'(Mode LIFO):n"; while (!intStack.empty()) { cout << intStack.top() << ", "; intStack.pop(); } cout << "\n\n"; return 0; } /* Fonction générique d'affichage des propriétés d'un stack */ template <class T, class C> void afficher_stack(stack<T, C>& qStack) { cout << "Taille = " << qStack.size(); if (!qStack.empty()) cout << "tête du stack = " << qStack.top(); cout << "nn"; } |
0