I have an assignment that I'm struggling with.
Write code based on referenced-based stack to implement the balance check of a user input string with ‘{’, ‘}’, ‘(’, ‘)’, and ‘[’, and ‘]’. For instance, if user inputs “(abc[d]e{f})”, your code should say that the expression is balanced.
I have the functions push / pop already written:
public void push(Object newItem) {
top = new Node(newItem, top);
} // end push
public Object pop(){
if (!isEmpty()) {
Node temp = top;
top = top.getNext();
return temp.getItem();
} else {
System.out.print("StackError on " +
"pop: stack empty");
return null;
} // end if
} // end pop
However, what I am struggling with is understanding how to create a new node for each character. Could somebody please help me?