Get Started

  • Pseudo code
  • The flow chart
  • Data structure queue & stack linked list

Pseudo code

Use three kinds of statements to express logic, that is to say, use JS keywords + sentence general idea to form the code structure, to sort out ideas.

The flow chart

Flowcharts are also a way of representing code, much more detailed than pseudocode. If the flowcharts are written exactly the way they are written, you are basically writing the code in language. It’s usually just a schematic drawing.

  • Sequential execution statement

  • Conditional statement

  • Looping statements

The data structure

• Provide first and last operations if the order makes sense [x, y] and [y, x] are different • Provide first and last operations if the order makes sense (x, y) and (y, X) hash = {1001 => ‘small square ‘, 1001 =>’ small red ‘}

Data structure = data form + operation

Different forms of data expose different operations currently used data structures • Arrays can be divided into queues, stacks, etc. • Hash tables are used to store key-value pairs

Queue

First in, first out FIFO array • Implement a restaurant call page, click [call] generate a number click [call] display [please X number] • select queue as data structure queue.push for queue, queue. Shift for queue practice call usage

• Spanqueue.innerText = queue.tostring ();

Current queue 1,2,3,4,5\

Convert an array to a string using toString, separating each value with a comma. spanQueue.innerText = JSON.stringify(queue); \

Current queue [1,2,3,4]\

• Note codesandbox.io has been upgraded to create unlimited free projects after logging in. Purpose: used to create vscode projects online.

The Stack (Stack)

LIFO array • Example JS functions call stack is a stack recursive function call stack. • code

支那

function f1(){let a = '1'; return a+f2()}
function f2(){let b = '2'; return b+f3()}
function f3(){let c = '3'; return c}
f1()
Copy the code

Linked Lists

  • The actual use
let array = [1.2.3]
array.__proto__ === Array.prototype
Array.prototype.__proto__ === Object.prototype
Copy the code

If you look at an object in this way, it’s a linked list

  • code
list = create(value)
node = get(index)
append(node, value)
remove(node)
travel(list, fn)
Copy the code

Deformation of linked lists

  • Two-way linked list

Each node has a previous pointing to the previous node

  • Circular linked list

The next of the last node points to the head node

Key-value Pairs

  • Difficult scene

Given that there are 10,000 key-value pairs in the hash table, what is the fastest way to read hash[‘ XXX ‘]

  • Hash [‘ XXX ‘] traverses all keys, O(n) sorts the key, uses binary lookup, 0(log2 n) indexes the ASCII number corresponding to the string, O(1) divides the index to get the remainder, O(1) conflicts, and continues

A tree (tree)

Multiple chains

  • code
let tree = createTree(value)
let node = createNode(value)
addChild(tree, node)
removeChild(node1, node2)
travel(tree)
Copy the code

This article is originally published by FJL. The copyright of this article belongs to me and Hungry People Valley