andy6804tw
12/5/2016 - 7:31 AM

LinkedList_Queue1.java

import java.util.*;

public class Main {

	public static void main(String[] args) {

		Queue<String> list = new LinkedList<>(); 
		list.offer("This is Queue1"); 
		list.offer("This is Queue2"); 
        list.offer("This is Queue3"); 
        Object o; 
        while(!list.isEmpty()) { 
            System.out.println(list.poll()); 
        } 
	}

}
import java.util.*;

class MyQueue {

	private LinkedList<String> linkedList;

	public MyQueue() {
		linkedList = new LinkedList<String>();
	}

	public void put(String name) {
		linkedList.addFirst(name);
	}

	public String get() {
		return linkedList.removeLast();
	}

	public boolean isEmpty() {
		return linkedList.isEmpty();
	}
}

public class Main {

	public static void main(String[] args) {

		MyQueue list = new MyQueue();
		list.put("This is Queue1");
		list.put("This is Queue2");
		list.put("This is Queue3");
		while (!list.isEmpty())
			System.out.println(list.get());
	}

}