Question: Consider the following program segment. Stack myStk = new Stack(); myStk.push('d'); myStk.push('i'); myStk.push('s'); myStk.push('t'); mystk.push('a'); myStk.push('n'); myStk.push('c'); mystk.push('e'); System.out.println(Content mystack at the beginning: mystk.toString()); +


Consider the following program segment. Stack myStk = new Stack(); myStk.push('d'); myStk.push('i'); myStk.push('s'); myStk.push('t'); mystk.push('a'); myStk.push('n'); myStk.push('c'); mystk.push('e'); System.out.println("Content mystack at the beginning: mystk.toString()); + Stack vowelstk - new Stack(); Stack tempStk = new Stack(); //Line AA *** missing codes System.out.println("Vowels: "+vowelstk.toString()); System.out.println("Consonants: "+tempStk.toString()); 1/Line BB *** diagrams of vowelstk and tempStk while (!tempStk.isEmpty()) { mystk.push(tempStk.pop(); } System.out.println("Content myStk at the end: " myStk.toString()); 1/Line CC *** diagram of myStk a) Write the missing code statements at Line AA to extract the vowels letters from mystk into the stack named vowelStk. The rest of the letters are moving into tempStk. (3 marks) b) Draw the diagrams of vowelstk and tempStk at Line BB and diagram of mystk at Line CC to represent the content in these data structures. Label the position of top where appropriate. (3 marks) c) Write the output of the program. (4 marks)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
