Lecture Notes on 23 Oct 2020 class Stack (object): def __init__ (self): self.stack = [] # add an item on the top of the stack def push (self, item): self.stack.append (item) # remove an item from the top of the stack def pop (self): return self.stack.pop() # check the item on the top of the stack def peek (self): return self.stack[-1] # check if the stack is empty def is_empty (self): return (len(self.stack) == 0) # return the number of elements in the stack def size (self): return (len(self.stack)) class Queue (object): def __init__ (self): self.queue = [] # add an item to the end of the queue def enqueue (self, item): self.queue.append (item) # remove an item from the beginning of the queue def dequeue (self): return (self.queue.pop(0)) # check if the queue if empty def is_empty (self): return (len(self.queue) == 0) # return the size of the queue def size (self): return (len(self.queue)) Operators: + - * / // % ** Operands: integers or floats Infix notation: operator between operands 2 + 3 = 5 9 - 7 = 2 4 * 6 = 24 45 / 15 = 3 Inherent Ambiguity in Infix Notation 2 + 3 * 5 = 17 2 + 3 * 5 = 25 Jan Lucasiewicz (1924) invented the Polish notation or Prefix notation where the operator precedes the operands: + 2 3 = 5 - 9 7 = 2 * 4 6 = 24 / 45 15 = 3 Charles Hamblin (1950) extended this notation to the Reverse Polish Notation (RPN) or Postfix notation. RPN leads to faster computation. Postfix Notation (Reverse Polish Notation) 2 3 + = 5 2 3 5 * + = 17 2 3 + 5 * = 25