Given the stacking order, determine if the stacking order is correct.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.