题目内容
const int maxstack = 10; // small value for testingclass Double_stack {public:Double_stack();bool empty_a() const;bool empty_b() const;bool full() const; //Same method checks both stacks for fullness.Error_code pop_a();Error_code pop_b();Error_code stacktop_a(Stack_entry &item)const;Error_code stacktop_b(Stack_entry &item) const;Error_code push_a(const Stack_entry&item);Error_code push_b(constStack_entry &item);private:int top_a; //index of top of stack a; -1 if emptyint top_b; //index of top of stack b; maxstack if emptyStack_entry entry[maxstack];};Double_stack::Double_stack(){ top_a = ;top_b = ; }Error_code Double_stack::push_a(const Stack_entry &item){ if (>= ) return overflow;entry[ ] = item;return success;}Error_code Double_stack::push_b(const Stack_entry &item){ if ( >= ) return overflow;entry[ ] = item;return success;}Error_code Double_stack::stacktop_a(Stack_entry &item)const{ if (== ) return underflow;item = ;returnsuccess;}Error_code Double_stack::stacktop_b(Stack_entry &item)const{ if ( == ) return underflow;item = ;return success;}bool Double_stack::full() const { return ; }bool Double_stack::empty_a() const { return ;}bool Double_stack::empty_b() const { return ; }Error_code Double_stack::pop_a(){ if (<= ) return underflow;else ;return success;}Error_code Double_stack::pop_b(){ if (>= ) return underflow;else ;return success;}typedef int Stack_entry;main(){ Double_stack e;e.push_a(1);e.push_a(2); e.push_a(3);e.push_b(1);e.push_b(2); e.push_b(3);int x;e.stacktop_a(x); cout << x;e.stacktop_b(x); cout << x;e.pop_a();e.pop_b();e.stacktop_a(x); cout << x;e.stacktop_b(x); cout << x;e.empty_a();e.empty_b();}
查看答案
搜索结果不匹配?点我反馈
更多问题