雙棧實現佇列

2021-06-10 07:15:26 字數 620 閱讀 9485

#include #include #include using namespace std;

templateclass cqueue

; ~cqueue(){};

void push_back(t data);

t pop_front();

bool empty();

public:

cqueue(t *pdata, int len);

private:

stackstack1;

stackstack2;

};templatecqueue::cqueue(t*pdata, int len)

templatet cqueue::pop_front()

t data = stack2.top();

stack2.pop();

return data;

} else

return -1;

}templatebool cqueue::empty()

void main()

cout<<"hahaaaaa"

}

雙棧實現佇列

有兩個棧stack1和stack2,在push時,直接壓入stack1 在pop時,判斷stack2是否為空,空則將stack1的資料壓入stack2,不空則只需將stack2的棧頂彈出。ifndef myqueue h define myqueue h include includeusing n...

棧 佇列 雙端佇列的實現

1.棧 class stack object 棧 def init self self.list def push self,item 新增新元素item到棧頂 def pop self 彈出棧頂元素 self.list.pop def peek self 返回棧頂元素 if self.list r...

利用雙棧實現佇列結構

用陣列封裝的佇列結構 public class mystack public void push int val throws exception data top val top public intpop throws exception top return this data top pub...