Saturday, April 27, 2019

Stack

The cases we usually need to consider to use stack:

  • We need to compare successive data items, use the peek method to get previous one to compare with current one, then pop up the peek or insert current one the the stack.
  • Usually need to return a consequence which the length is different from the one passed.

  1. Math
    • iterate the array
      • push to stack when it's a number
      • otherwise pop two items to calculate
        ["4", "13", "5", "/", "+"] -> (4 + (13 / 5)) -> 6
  2. dfd

No comments:

Post a Comment