Home / Expert Answers / Computer Science / a-consider-the-following-code-assume-that-pop-returns-the-object-stored-in-the-stack-nbsp-queu-pa459

(Solved): a) Consider the following code(assume that pop() returns the Object stored in the stack):  Queu ...



a) Consider the following code(assume that pop() returns the Object stored in the stack):

  Queue<Integer> q = new LinkedQueue<Integer>();
  Stack<Integer> s = new LinkedStack<Integer>();
  s.push(1);
  s.push(8);
  s.push(7);

  while (!s.isEmpty()) {
    q.enqueue(s.pop());
  }
  System.out.print(q.dequeue() + ", " + q.dequeue()); // note: a comma and a space character separate the values.


What is the output that is printed when this code executes? (enter exactly what is printed).


b) Consider the following array: 9, 2, 3, 8, 0

We apply selection sort to sort this array in ascending order.

What is the state of the array after the first two rounds of the outer loop?




We have an Answer from Expert

View Expert Answer

Expert Answer


Ans a.) After inserting stack values, stack will look like this 7 8 1 because stack is last-in first
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe