package com.xdl.data_stru;
/**
* @author xudaolong 栈:先进后出,如取井水;
*
*/
@SuppressWarnings("unused")
public class Day_Three_SeqStack<E> {
private Object[] data;
private int top;
private void init(int maxnum) {
this.data = new Object[maxnum];
this.top = -1;// 且当做是约定吧
}
/* 判断是否满 */
private boolean stack_full() {
if (this.top == this.data.length - 1) {
return false;
}
return true;
}
private boolean push(E data) {
if (!stack_full()) {
this.top = this.top + 1;
this.data[this.top] = data;
return true;
}
return false;
}
@SuppressWarnings("unchecked")
private E pop() {
if (!is_empty()) {
this.top = this.top - 1;
return (E)this.data[this.top + 1];
}
return null;
}
@SuppressWarnings("unchecked")
private E get_top() {
if (!is_empty()) {
return (E)this.data[this.top];
}
return null;
}
private boolean is_empty() {
if (this.top == -1) {
return true;
}
return false;
}
}
java 数据结构之 顺序存储结构 栈
最新推荐文章于 2022-12-17 20:19:23 发布