/**
* 用陣列封裝的佇列結構
*/public
class
mystack
public
void
push
(int val)
throws exception
data[top]
= val;
top ++;}
public
intpop()
throws exception
top--
;return
this
.data[top];}
public
boolean
isempty()
}
/**
* 用兩個棧模擬的佇列結構
*/public
class
myqueue
public
void
push
(int val)
throws exception
public
intpop()
throws exception
int result = stack2.
pop();
while
(!stack2.
isempty()
)return result;
}}
到此乙個簡單的佇列就算完成了 …
接下來我們來測試一下大致的存資料和取資料這兩個功能吧
public
class
main
}
看起來好像是那麼回事噢,好的,拜拜~ 溜了溜了~ 雙棧實現佇列
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 pri...
雙棧實現佇列
有兩個棧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...