我是靠谱客的博主 听话白开水,这篇文章主要介绍双端队列实现栈,现在分享给大家,希望可以做个参考。


4.3 编写一个基于上机作业4.2的Deque类的栈类。这个栈类应该与 stack.java程序(清单4.1)中的StackX类具有机同的方法和功能。


复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public class StackY { private DuQueue stackQueue; public StackY(int size){ stackQueue = new DuQueue(size); } public void push(long value){ stackQueue.insertRight(value); } public long pop(){ return stackQueue.removeRight(); } public long peek(){ return stackQueue.peekRight(); } public boolean isEmpty(){ return stackQueue.isEmpty(); } public boolean isFull(){ return stackQueue.isFull(); } }
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public class StackYApp { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub StackY theStack = new StackY(5); System.out.println("Stack is Empty : " + theStack.isEmpty()); System.out.println("Stack is Full : " + theStack.isFull()); theStack.push(20); theStack.push(40); theStack.push(60); theStack.push(80); theStack.push(90); System.out.println("Stack is Empty : " + theStack.isEmpty()); System.out.println("Stack is Full : " + theStack.isFull()); while(!theStack.isEmpty()){ long value = theStack.pop(); System.out.print(value); System.out.print(" "); } } }

最后

以上就是听话白开水最近收集整理的关于双端队列实现栈的全部内容,更多相关双端队列实现栈内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(66)

评论列表共有 0 条评论

立即
投稿
返回
顶部