Formative Assessment 3: Memory Diagrams

ArrayStack

ArrayStack Start

Here is an initial memory diagram of an ArrayStack. Choose the final state from the options below after executing the code provided. Use the definition of the ArrayStack we discussed in class and implemented in lab.

s.push(2);
s.push(3);
s.push(5);
s.push(8);
s.pop();
s.pop();
s.push(1);

ArrayStack Choices

ListNode

ListNode Start

Choose the memory diagram below to show the result of executing the following lines of Java code.

t = r.getNext().getNext();
r.setNext(t.getNext());
t.setItem(5);
t.getNext().setNext(r);

ListNode Choices

Come to office hours ready to explain your choices. Be prepared to analyze a similar memory diagrams.