public static Integer calcs(String postFix) {
StackInterface<Character> stack = new LinkedStack<Character>(); // instantiate Character stack
Integer result = new Integer(0);
Node<Integer> num1, num2;
Integer int1 = new Integer(0); // declare address to each variable object
Integer int2 = new Integer(0);
num1 = new Node<Integer>(int1, null);
num2 = new Node<Integer>(int2, null);
num1.setNext(num2); // link two nodes
// print linked nodes
Node<Integer> pointer = num1;
Integer number = pointer.getData();
System.out.println("head = " + number);
pointer = pointer.getNext();
number = pointer.getData();
System.out.println("tail = " + number);
System.out.println();
Node<Integer> node1 = new Node<Integer>(1, null);
Node<Integer> node2 = new Node<Integer>(2, null);
node1.setNext(node2);
node2.setNext(node1);
for(Node<Integer> i = node1; i != null; i = i.getNext()) {
System.out.println(i.toString());
}
I'm trying to make PostFix calculator using Node.
How would I make it work to add, for example, if two integers are 3 and 5, which should equal to 8?
for(int i = 0; i < postFix.length(); i++) {
Character chars = new Character(postFix.charAt(i)); // separate each character
switch(chars) {
case '+':
stack.pop(); // pop operators
if(chars == '+') {
result = node1 + node2;
}
break;
I think my if statements are wrong or perhaps the arrangement of node.. can anyone help me out here?
Thanks!