Use Queue as a Stack

package com.zhoubo.concurrent.collection;

import java.util.LinkedList;
/**
 * 用linkedList实现stack(LIFO)
 * @author Administrator
 *
 */
public class QStack {
	public  LinkedList<String> stack = new LinkedList<String>();
	
	public void add(String str){
		stack.add(str);
	}
	
	public String pop(){
		return stack.removeLast();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		QStack qStack = new QStack();
		qStack.stack.add("jim");
		qStack.stack.add("lily");
		qStack.stack.add("lucy");
		System.out.println(qStack.pop());
		System.out.println(qStack.pop());
		System.out.println(qStack.pop());
		
	}

}

 

你可能感兴趣的:(Collection)