Data deconstruction

  1. Queue & stack
  2. The list
  3. Hash table
  4. The tree

1. Queue & stack

  • The queue
    • FIFO array
    • scenario
      • The restaurant your turn
    • Push on the stack unshift off the stack

(Image from Hungry Man Valley)

  • The stack
    • Last-in, first-out array
    • scenario
      • Enclosed elevator
    function fn1(){
        let a = 1
        return a + fn2()
    }
    function fn2(){
        let b = 2
        return b + fn3()
    }
    function fn3(){
        let c = 3
        return c
    }
    console.log(fn1()) 
Copy the code

The procedure for executing the code above is

2. List

  • One object connects to another object
  • scenario
    • Prototype chain pattern
  • Lists can be added, deleted, or checked (using recursion)

3. The hash table

  • Used to store a key-value pair
  • The more data you store, the longer it takes to read.

Tree of 4.

  • Tree
    • Multiple chains
    • scenario
      • County-level cities in China
      • Nodes of web pages
  • You can add, delete, change, and check just like a linked list (using recursion)