Utilisation de stack en paramètre d’une fonction

Author:

 list, list
Download


#include 
#include 
#include

#include 
using namespace std;

template< typename T > void pushElements( T &refStack )
{
   for ( int i = 0; i < 100; i++ )
   {
      refStack.push( i );
      cout << refStack.top() << ' ';
   }
}

template< typename T > void popElements( T &refStack )
{
   while ( !refStack.empty() )
   {
      cout << refStack.top() << ' ';
      refStack.pop();
   }
}

int main()
{
  stack< int > deqStack;

   cout << "Ajoute des élément dans le stack: ";
   pushElements( deqStack );
   cout << endl << endl;

   cout << "Servir les éléments du 'stack': ";
   popElements( deqStack );
   cout << endl;
   return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *