java中自带实现堆栈与队列的方法
堆栈
package test.java;
import java.util.Stack;
/**
* 堆栈类的使用
* @author KING
*/
public class TestStack {
/*
* public class Stackextends VectorStack 类表示后进先出(LIFO)的对象堆栈。它通过五个操作对类
* Vector 进行了扩展 ,允许将向量视为堆栈。它提供了通常的 push 和 pop 操作,以及取堆栈顶点的 peek 方法、测试堆栈是否为空的
* empty 方法、在堆栈中查找项并确定到堆栈顶距离的 search 方法。
*/
public static void main(String[] args) {
Person person1 = new Person();
person1.setName("111");
Person person2 = new Person();
person2.setName("222");
Person person3 = new Person();
person3.setName("333");
Person person4 = new Person();
person4.setName("444");
Stack stack = new Stack();
stack.push(person1);// 把项压入堆栈顶部
stack.push(person2);