- 栈的顺序存储示意图
![栈顺序存储示意图](/keviness/Algorithms/raw/master/Algorithms_Java/Notes/img/stack_sequence.png)
class Node
{
public int data;
public String name;
public Node(String name, int data)
{
this.name = name;
this.data = data;
}
public String toString()
{
return "name:"+this.name+" data:"+this.data;
}
}
public Node[] stack;
public int top;
public int length;
public Stack(int length)
{
stack = new Node[length];
this.top = -1;
this.length = length;
}
public boolean isEmpty()
{
return this.top == -1;
}
public boolean isFull()
{
return this.top == this.length;
}
public void push(Node target)
{
if (this.isFull())
{
System.out.println("The stack is full!");
return;
}
this.top++;
stack[this.top] = target;
System.out.println("The push into the stack successfully!");
}
public Node pop()
{
if (this.isEmpty())
{
System.out.println("The stack is empty!");
return null;
}
Node temp = stack[this.top];
this.top--;
System.out.println("Pop successfully!");;
return temp;
}