栈的实现
2019-06-25 本文已影响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;
}
}