本文共 1413 字,大约阅读时间需要 4 分钟。
1,Stack不是一个已经定义的类型。应该小写s的 stack
class Queue {public: // Push element x to the back of queue. void push(int x) { pushStack.push(x); } // Removes the element from in front of queue. void pop(void) { if (empty()){ // EXCLUDE IN THIS PROBLEM } if (popStack.empty() && !pushStack.empty()){ tansportation(); } return popStack.pop(); } // Get the front element. int peek(void) { if (empty()){ // EXCLUDE IN THIS PROBLEM } if (popStack.empty() && !pushStack.empty()){ tansportation(); } return popStack.top(); } // Return whether the queue is empty. bool empty(void) { return pushStack.empty() && popStack.empty(); } void tansportation(void){ if (popStack.empty() && !pushStack.empty()){ while(!pushStack.empty()){ int elem = pushStack.top(); popStack.push(elem); pushStack.pop(); } } }private: stack pushStack; stack popStack;};
转载地址:http://rcpbb.baihongyu.com/