Question: (it would be a great help if you could answer all the questions embedded in the code but I had to choose the order if

(it would be a great help if you could answer all the questions embedded in the code but I had to choose the order if importance it would be questions 3,5,1,7,2,4,6)

import java.util.Arrays; import java.util.LinkedList; import java.util.Queue; import java.util.Stack;

/* * Practice Problem for Week 6: * * Look at the code and answer the questions included as comments. * Turn in your responses in a separate document (e.g. a .pdf or .doc). */

public class Stack_Q {

public static void main(String[] args) { // 1. What do the following 3 lines do? Stack stringStack = new Stack(); Queue initialQueue = new LinkedList(Arrays.asList("Computer", "Computers", "Fun", "Fantastic", "Science","Is", "Great", "Awesome")); Queue finalQueue = new LinkedList(); // 2. What does the line below do? stringStack.push(initialQueue.remove()); finalQueue.add(initialQueue.remove()); for(int i = 0; i < 3; i++) { initialQueue.add(initialQueue.remove()); stringStack.push(initialQueue.remove()); stringStack.push(initialQueue.remove()); initialQueue.add(finalQueue.remove()); finalQueue.add(initialQueue.remove()); finalQueue.add(stringStack.pop()); } // 3. Create graphical representations of the initialQueue // and the stringStack structures and contents. // You can ignore finalQueue, since LinkedLists come later. // (You may hand draw these or create them some other way) // Only consider the contents they contain at THIS point in the program. // 4. Explain what happens in the following loop for(int j = 0; j < finalQueue.size(); j++) { String temp = finalQueue.remove(); System.out.print(temp + " "); finalQueue.add(temp); } // 5. What is the value of (String) temp now? stringStack.pop(); stringStack.pop(); String toPrint = stringStack.pop(); // 6. What is the purpose of the following line? System.out.println(); System.out.println(toPrint); // 7. Create graphical representations of the initialQueue // and the stringStack structures and contents. // (You may hand draw these or create them some other way) // Only consider the contents they contain at THIS point in the program.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The provided question is incomplete because it refers to questions embedded in code without specifically listing those questions in a detailed manner ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!