Complete the code to create a new node in the stack.
Node newNode = new Node([1]);The new node should be created with the given value to push onto the stack.
Complete the code to update the top pointer after pushing a new node.
newNode.next = [1];
top = newNode;We set the new node's next to the current top, then update top to the new node.
Fix the error in the pop method to correctly remove the top node.
if (top == null) return null; Node temp = top; top = [1]; return temp.value;
After saving the top node in temp, update top to top.next to remove the top node.
Fill both blanks to check if the stack is empty and return the correct boolean.
public bool IsEmpty() {
return [1] == [2];
}The stack is empty if the top pointer is null.
Fill all three blanks to implement the Peek method that returns the top value without removing it.
public int Peek() {
if ([1] == [2]) {
throw new InvalidOperationException("Stack is empty");
}
return [3].value;
}Peek checks if top is null (empty stack), then returns top.value without removing it.
