/* Redo Lab 8-1 using class*/
/* All data members MUST BE PRIVATE */
/* Do not change main */
#include <iostream>
#define MAX_NEG -1000000000
using namespace std;
class stack_arr_t {
public:
/*
* Must include the constructor, dynamic_push, dynamic_pop, and show functions.
*/
private:
/*
* Data members must be put here !!
*/
};
/*
* Member function definitions should be put here!! Add stack_arr_t:: to their names.
* Constructor's name must be the same as the class name. Do not specify any return type for the constructor!
*/
/* Do not change main()!! Penalty points may be applied !!
* 請勿改 main,否則可能被扣分!!
*/
int main(){
int input_size, temp, max_size, pop_size;
/* input stack's max size */
cin >> max_size;
/* constructor will be called here */
stack_arr_t my_stack(max_size);
/* input elements to be pushed */
cin >> input_size;
int i;
for(i=0; i<input_size; ++i){
cin >> temp;
my_stack.dynamic_push(temp);
}
/* input number of elements to be popped */
cin >> pop_size;
for(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
5
21 3 4 5 8
4
8 5 4 3
Stack contains 1 element(s)
21
top = 1, max_size = 4