Question: Q6: IN JAVA: DRAW the memory picture just after each new listitem is created class ListItem { String data; ListItem next; public class StrangeExample f
Q6: IN JAVA: DRAW the memory picture just after each new listitem is created
class ListItem { String data; ListItem next; public class StrangeExample f public static void main (String[] argv) // Make one instance and put a string in the data field ListItem firstnew ListItem); first.data - "Yes minister"; /Make a second one. ListItem second - new ListItem); second.data - "Seinfeld"; Now link them: make the first one point to the second. first.next - second; /7 Make a third and make the second point to the third. ListItem third = new ListItem(); third.data "Cheers" second.next - third; // Make a fourth etc. ListItem fourth = new ListItem(); fourth.data - "Frasier"; third.next - fourth; ListItem last -new ListItem); last.data - "Simpsons"; fourth.next last; // Now print. Note the extensive use of the dot-operator. System.out.println ("First: " + first.data); System.out.println ( "Second: " + first.next.data); System.out.println ("Third: " + first.next.next.data); System.out.println ( "Fourth:" + first.next.next.next.data); System.out.println ( "Last: "+ first.next.next.next.next.data); System.out.println ( "Last (alt):"last.data) In-Class Exercise 6: Draw the memory picture after each neW ListItem has been created
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
