栈的实现
作者:
激扬飞雪 | 来源:发表于
2019-06-25 11:32 被阅读0次package com.data.cn;
/**
* Created by kaily on 17/5/10.
*/
public class Stack {
private int top;
private int max;
private long values[];
public Stack(int max) {
this.max = max;
values = new long[max];
top = -1;
}
public boolean isEmpty() {
return top == -1;
}
public boolean isFull() {
return top == max - 1;
}
public long pop() {
if (isEmpty()) {
return -1;
}
return values[top--];
}
public long peek() {
if (isEmpty()) {
return -1;
}
return values[top];
}
public void push(long value) {
if (isFull()) {
return;
}
values[++top] = value;
}
}
本文标题:栈的实现
本文链接:https://www.haomeiwen.com/subject/tdxtcctx.html
网友评论