preface
After the first stage of learning, THE information of my learning algorithm was confirmed. This article mainly talks about stack, queue, binary tree and other data structure concept and specific application
Don’t look back, but just push forward!
1. The stack
Linear table, limited operation, first in last out
This topic examines various logical operations of strings, and the author implements them as follows:
function bong(arr) { let ret = [] for(let i of arr) { if(i === 'C') { if(ret.length) { ret.pop() } }else if(i === 'D') { let pre = ret.slice(-1) ret.push(pre * 2) }else if(i === '+') { let pre1 = ret.slice(-1) let pre2 = ret.slice(-2, -1) ret.push(pre1[0] + pre2[0]) }else { ret.push(i) } } return ret.reduce((acc, num) => (acc + num), 0) }Copy the code