What is the output of the following code? Recall that stacks and queues print in an [a, b, c] format from bottom/front to top/back. Stack s = new Stack(); Queue q = new LinkedList(); s.push("how"); s.push("are"); s.push("you"); while (!s.isEmpty()) { q.add(s.pop()); } System.out.println(q);

Respuesta :

Answer:

[you, are, how]

Explanation:

The output for given code will be [you, are, how]. Pop gives the mist recently added element in the stack so order is reversed.

ACCESS MORE

Otras preguntas