import java.util.Deque;
import java.util.ArrayDeque;
public class TestDeque {
    public static void main(String[] args) {
        //ArrayList<Integer> justInts=new ArrayList<>();
        Deque<String> deque=new ArrayDeque<>();

        // deque as a Stack: push 3 plates
        System.out.println("***** Using deque as a Stack");
        deque.addFirst("Top plate");
        deque.addFirst("Middle plate");
        deque.addFirst("Bottom plate");

        System.out.println("  Pushed 3 plates: ");
        for (String item : deque) {
            System.out.println(item);
        }

        // pop the last item
        String removedPlate = deque.removeLast();
        System.out.println("  Removed " + removedPlate + " from the stack, remaining plates are:");
        for (String item : deque) {
                System.out.println(item);
        }

        // remove all items:
        deque.clear();

        // deque as a Queue: add 3 persons
        System.out.println("***** Using deque as a Queue");
        deque.addLast("First person in line");
        deque.addLast("Next person");
        deque.addLast("Last person");
        System.out.println("  Added 3 persons to the queue:");
        for (String item : deque) {
            System.out.println(item);
        }

        // serve the first person in the queue (head of the line)
        String removedPerson = deque.removeFirst();
        System.out.println("  Served " + removedPerson + " from the queue, remaining persons are:");
        for (String item : deque) {
            System.out.println(item);
        }
    }
}