Re-write Lec 11 using templates.
Re-define the Stack_t as a generic class template as follows.
template <class T>
class Stack_t {
/* your member functions should take any class T
* modify your data member well so it takes any class T, too
*/
};
Use the following main. Do not change it.
int main(){
int input_size, max_size, pop_size;
double temp;
/* input stack's max size */
cin >> max_size;
/* constructor is to be called */
Stack_t<double> my_stack(max_size);
/* input elements to be pushed */
cin >> input_size;
for(int i=0; i<input_size; ++i){
cin >> temp;
my_stack.dynamic_push(temp);
}
/* input number of elements to be popped */
cin >> pop_size;
for(int i=0; i < pop_size-1; ++i){
cout << my_stack.dynamic_pop() << ' ';
}
if (0 != pop_size){
cout << my_stack.dynamic_pop() << endl;
}
my_stack.show();
return 0;
}
4
9
21.2 6 3 65.1 7 91.333 4 5.23 8
0
Stack contains 9 element(s)
21.2 6 3 65.1 7 91.333 4 5.23 8
top = 9, max_size = 16