Outline



Reminder: stack ADT



array implementation, linked implementation



Node class

    public class Node {
      private String item;
      private Node next;  
      /* methods */
    }



In-class exercise

On your own, draw a diagram of the result of this code:
Node node1 = new Node("string1", null);
Node node2 = new Node("string2", null);
Node node3 = new Node("string3", null);
Node node4 = new Node("string4", null);
Node node5 = new Node("string5", null);
node1.setNext(node5);
node2.setNext(node4);
node3.setNext(node2);
node4.setNext(null);
node5.setNext(node3);



Linked list stack implementation



Linked list stack performance



Java notes



Linked lists



Object usage



Stack usage: balanced parentheses



In-class exercise

everyone together, figure out what this code does



Stack usage: infix to postfix conversion



In-class exercise

  1. --- 5 + 5 / 3
  2. --- 5 / 5 + 3
  3. --- 5 * 5 * 3
  4. --- (5 + 5) / 3
  5. --- ((5 + 4 - 2 / 3) * 2 + (7 * 2 - 8)) % 3