What is the output after the following Java program is executed? Assume the clas
ID: 3692356 • Letter: W
Question
What is the output after the following Java program is executed?
Assume the class Lab10_Ex1 defines the missing methods to print.
//Client for user-defined classes
//LinkedStackClass and QueueClass
//Methods (missing here): printStack, printQueue
import java.util.*;
public class Lab10_Ex1 {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
LinkedStackClass<Character> s = new LinkedStackClass<Character>();
QueueClass<Character> q = new QueueClass<Character>(10);
Character ch;
for(ch = 'A'; ch <= 'H'; ch++)
s.push(ch);
System.out.println("Initial stack is: ");
printStack(s);
for(int i = 1; i <= 4; i++) {
s.pop();
q.enqueue(s.peek());
s.pop();
q.enqueue(s.peek());
s.push(q.front());
q.dequeue( );
}
System.out.println(" Final stack is: ");
printStack(s);
System.out.println(" The queue is: ");
printQueue(q);
}
//method definition for printStack
//method definition for printQueue
}
Explanation / Answer
Initial Stack is: H G F E D C B A.
Final Stack is: E C B A.
The queue is: E D D C.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.