Stack push-in, pop-up sequence

Source: Internet
Author: User

"Title description"Enter a sequence of two integers, and the first sequence represents the stacking order of the stack, judging whether the second sequence is the pop-up order for the stack. Assume that all the numbers that are pressed into the stack are not equal. For example, the sequence 1,2,3,4,5 is the indentation order of a stack, and the sequence 4,5,3,2,1 is a pop-up sequence corresponding to the stack sequence, but 4,3,5,1,2 is not likely to be the pop-up sequence of the stack sequence. "Code Implementation"
1#include <iostream>2#include <vector>3 4 using namespacestd;5 6 BOOLIspoporder (vector<int> PUSHV, vector<int>POPV) {7     if(pushv.size () = =0)8         return false;9Vector <int>Vec;Ten      for(inti =0, j =0; I < pushv.size (); i++) One     { AVec.push_back (Pushv[i]);//re-simulate the initial stack process -          while(J < Popv.size () && vec.back () = =Popv[j]) -         { theVec.pop_back ();//re-simulate the initial stack-out process -J + +; -         } -     } +     //successful simulation succeeds, the element should all pop up, return to true, otherwise there will be no element eject, resulting in non-null, return to False -     returnvec.empty (); + } A  at intMainvoid) - { -vector<int> pushlist{1,2,3,4,5 }; -vector<int> poplist{4,3,5,1,2 }; -cout << Ispoporder (pushlist, poplist) <<Endl; -System"Pause"); in     return 0; -}

Stack push-in, pop-up sequence

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.