package com.part02;
public class StackX {
int size;
long[] stackArray;
int top;
public StackX(int max){
size=max;
stackArray=new long[max];
top=-1;
}
//push value
public void push(long value) {
stackArray[++top]=value;
}
//pop a value
public long pop() {
return stackArray[top--];
}
//peek at top of stack
public long peek() {
return stackArray[top];
}
//true if stack is empty
public boolean isEmpty() {
return (top==-1);
}
//true if stack is full
public boolean isFull(){
return (top==size-1);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
StackX stackX= new StackX(100);
stackX.push(12);
stackX.push(34);
stackX.push(45);
stackX.push(32);
while(!stackX.isEmpty())
{
long value =stackX.pop();
System.out.println(value+ " ");
}
}
}
数据结构与算法——数组实现Stack代码
最新推荐文章于 2024-08-23 17:37:15 发布