summaryrefslogtreecommitdiffstats
path: root/Bachelor/Prog2/Stack/Tst_test.cpp
blob: 5e9e9f8c7356f4204bae49d6c8f12cc094a1bebe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Test driver for Stack template.

// Function main uses a function template to manipulate objects of type Stack< T >.

// Modification: use non-type parameter 'elements' in Stack-template



#include <iostream>

using std::cout;

using std::cin;

using std::endl;



#include <string>

using std::string;



#include "tstack1.h"



// Function template to manipulate Stack< T >

template< class T, int elements > 

void testStack( 

   Stack< T, elements > &theStack,   // reference to the Stack< T >

   T value,                // initial value to be pushed

   T increment,            // increment for subsequent values

   const char *stackName ) // name of the Stack < T > object

{

   cout << "\nPushing elements onto " << stackName << '\n';



   while ( theStack.push( value ) ) { // success true returned

      cout << value << ' ';

      value += increment;

   }



   cout << "\nStack is full. Cannot push " << value 

        << "\n\nPopping elements from " << stackName << '\n';



   while ( theStack.pop( value ) )  // success true returned

      cout << value << ' ';



   cout << "\nStack is empty. Cannot pop\n";

}



int main()

{

   Stack< double, 5 > doubleStack;   

   Stack< int, 10 > intStack;

   Stack< string, 5 > stringStack;



   testStack( doubleStack, 1.1, 1.1, "doubleStack" );

   testStack( intStack, 1, 1, "intStack" );

   testStack( stringStack, string("Eins"), string("UndEins"), "stringStack" );



   return 0;

}