Mark As Completed Discussion

Keep in mind that in our implementation, we're inserting data into a node. To insert within a node, we need to not only insert our item but also the reference to the next node.

In the prior snippet, we were creating a new node using the Node(int item, Node next) constructor. Inside that node, we pushed our item, creating a reference to top as the next node, and assigned top to be this new node.

1pop() {
2  if (this.top !== null) {
3    this.top = this.top.next;
4  }
5  return null;
6}