队列-实现栈
来源:互联网 发布:虚拟充值软件靠谱吗 编辑:程序博客网 时间:2024/06/06 23:01
package d_queue.E_queue_stack;
public class Deque {
private int[] arr;
private int maxSize;
private int left;
private int right;
private int aItems;
public Deque(int s) {
maxSize = s;
arr = new int[maxSize];
right = 0;
left = -1;
aItems = 0;
}
public void push(int key) {
if (right == maxSize)
right = 0;
arr[right++] = key;
aItems++;
}
public int pop() {
int temp = -1;
if (aItems != 0) {
if (left == -1)
left = maxSize - 1;
// 锟斤拷锟秸碉拷锟斤拷锟斤拷锟�
while (arr[left--] == 0) {
if (left == -1)
left = maxSize - 1;
}
temp = arr[left+1];
}
aItems--;
return temp;
}
public boolean isEmpty() {
return aItems == 0;
}
public boolean isFull() {
return aItems == maxSize;
}
}package d_queue.E_queue_stack;
/**
* 双锟剿讹拷锟斤拷 支锟街伙拷锟斤拷式
*
* @author Administrator
*
*/
public class DequeApp {
public static void main(String[] args) {
Deque theDeque = new Deque(8);
theDeque.push(453);
theDeque.push(453);
theDeque.push(4);
theDeque.push(453);
theDeque.push(417);
theDeque.push(173);
// theDeque.insertRight(103);
// theDeque.insertRight(3);
while (!theDeque.isEmpty()) {
System.out.println(theDeque.pop());
}
}
}
public class Deque {
private int[] arr;
private int maxSize;
private int left;
private int right;
private int aItems;
public Deque(int s) {
maxSize = s;
arr = new int[maxSize];
right = 0;
left = -1;
aItems = 0;
}
public void push(int key) {
if (right == maxSize)
right = 0;
arr[right++] = key;
aItems++;
}
public int pop() {
int temp = -1;
if (aItems != 0) {
if (left == -1)
left = maxSize - 1;
// 锟斤拷锟秸碉拷锟斤拷锟斤拷锟�
while (arr[left--] == 0) {
if (left == -1)
left = maxSize - 1;
}
temp = arr[left+1];
}
aItems--;
return temp;
}
public boolean isEmpty() {
return aItems == 0;
}
public boolean isFull() {
return aItems == maxSize;
}
}package d_queue.E_queue_stack;
/**
* 双锟剿讹拷锟斤拷 支锟街伙拷锟斤拷式
*
* @author Administrator
*
*/
public class DequeApp {
public static void main(String[] args) {
Deque theDeque = new Deque(8);
theDeque.push(453);
theDeque.push(453);
theDeque.push(4);
theDeque.push(453);
theDeque.push(417);
theDeque.push(173);
// theDeque.insertRight(103);
// theDeque.insertRight(3);
while (!theDeque.isEmpty()) {
System.out.println(theDeque.pop());
}
}
}
0 0
- 队列实现栈和栈实现队列
- 栈实现队列&&队列实现栈
- 栈实现队列,队列实现栈
- 队列实现栈,栈实现队列
- 数据结构--队列实现栈&栈实现队列
- 双队列实现栈
- 两个栈实现队列
- 用栈实现队列
- 两个队列实现栈
- 两个栈实现队列
- 双栈实现队列
- LinkedList实现栈,队列
- 栈实现队列(模板)
- 双栈实现 队列
- 两个栈实现队列
- 两个栈实现队列
- 两个队列实现栈
- 两个栈实现队列
- 双向队列
- 如何在Linux下干净卸载db2数据库
- git warning: LF will be replaced by CRLF in 解决办法
- 队列-运算后缀表达式
- mysql 时间索引失效
- 队列-实现栈
- sql执行顺序
- 5.2 链表
- JavaSE_27th_数组——冒泡排序
- 如果看了此文你还不懂傅里叶变换,那就过来掐死我吧【完整版】
- 链表-A-单链表
- Linux~连接windows的ftp,unzip出现的问题
- 人工智能是好是坏
- 实习重点单词查阅