205k views
2 votes
942→856→481→92

'top' is a reference variable that points to the node containing 942 , and 'count' is an internal int that holds the count of nodes (currently 4).
The following code is ran:
Integer firstPop * mystack pop0;
lnteger secondPop = myStack.pop0:
mystack push(firstPop):
mystack push(537):
myStackpush(secondPopl: myStack.push(560):
Select all of the following that are true at the end of this code.
1) The variable secondPop refers to 481
2) The integer held by secondPop is now the ekment contained by the node referenced through top's next pointer
3) The variable firstPop refers to 942
4) The integer held by firstPop is now the element contained by the node referenced through the top pointer
5) The count is currently equal to 6
6) The element 537 is contained by the third node in this stack (Where 'top' is considered the first node)
7) 92 is the only integer that didn't change position in the LinkedStack

User Dbloom
by
7.8k points

1 Answer

1 vote

Final answer:

At the end of the code, the variables 'secondPop' and 'firstPop' refer to different values and the count of nodes has changed.

Step-by-step explanation:

At the end of the code, the following statements are true:

  1. The variable secondPop refers to 856.
  2. The integer held by secondPop is now the element contained by the node referenced through top's next pointer, which is 481.
  3. The variable firstPop refers to 942.
  4. The integer held by firstPop is still the element contained by the node referenced through top, which is 942.
  5. The count is currently equal to 5, as one element has been popped off the stack.
  6. The element 537 is contained by the fourth node in this stack (where top is considered the first node).
  7. 92 is the only integer that didn't change position in the LinkedStack.

User Holian
by
7.3k points