棧和隊列
(1)Stack繼承了Vector
(2)LinkedList實現了Queue接口
package com.jlz;
import java.util.*;
/**
*
* @author Jlzlight Stack Queue
*/
public class TestStack {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Stack<Object> stack = new Stack<Object>();
// 入棧
stack.push("C");
stack.push("B");
stack.push("A");
// 獲取棧頂元素
System.out.println(stack.peek());
// 出棧
System.out.println(stack.pop());
System.out.println(stack.pop());
System.out.println(stack.pop());
// LinkedList實現Queue接口
Queue<Object> queue = new LinkedList<Object>();
// 入隊列
queue.add("A");
queue.add("B");
queue.add("C");
// 隊首元素
System.out.println(queue.peek());
// 出隊列
System.out.println(queue.poll());
System.out.println(queue.poll());
System.out.println(queue.poll());
}
}