If the new node we created is null (nothing), how is it not referring to the stack as empty but instead checks if the stack is full?
//push() function public void push(int x) { //create a new node and allocate memory Node node = new Node(); //check if the stack is full i.e check for stack overflow if(node == null) { System.out.println("\n Stack is full. Stack Overflow!"); return; } node.data = x; node.next = head; head = node; } //check for an empty stack public boolean isEmpty() { return head == null; }
https://stackoverflow.com/questions/66937400/how-exactly-node-null-checks-if-the-stack-is-full April 04, 2021 at 09:59AM
没有评论:
发表评论