1 varINS = [1, 2, 3, 4, 5];2 varOuts = [3, 4, 5, 2, 1];3 vartemp =ins;4 varnum, i = 0, Len;5 6 /**7 * ins into the stack order8 * Outs out Stack order9 * Temp Temporary array, save in stack orderTen * num is the subscript of the current out-of-stack node in the temporary array One * Len Temp Array length-1 A * - */ -(function(temp, outs) { the if(INS = =NULL|| temp = =NULL){ -Console.log ("Cannot be empty"); - } - for(i = 0; i < outs.length; i++) { +num =Temp.indexof (Outs[i]); -Len = temp.length-1; + if(num > 0 | | num <Len) { A if((outs[i + 1] = = temp[num-1]) | | (outs[i + 1] = = Temp[num + 1])) { atTemp.splice (NUM, 1); - Continue; - } -Console.log (' Not the right stack order ')); - return false; -}Else if(num = = 0) { in if(outs[i + 1] = = Temp[num + 1]) { -Temp.splice (NUM, 1); to Continue; + } -Console.log (' Not the right stack order ')); the return false; *}Else if(num = =Len) { $ if(outs[i + 1] = = Tem[num-1]) {Panax NotoginsengTemp.splice (NUM, 1); - Continue; the } +Console.log (' Not the right stack order ')); A return false; the}Else { +Console.log (' Not the right stack order ')); - return false; $ } $ } -Console.log ("correct"); -}) (temp, outs);
Given the stacking order, determine if the stacking order is correct.