标签:










#ifndef IS_STACK_SEQ_H#define IS_STACK_SEQ_H#include<stack>#include<iostream>bool isStackSeq(int *arrPush,int *arrPop,int Length){if(arrPush==NULL||arrPop==NULL||Length==0){throw("invalid input ");return false;}std::stack<int> stack_pop;std::stack<int> stack_push;for(int i=0;i<Length; i++){stack_pop.push(arrPop[i]);}int *arrPushEnd=arrPush+Length-1;while(arrPush<=arrPushEnd){while(*arrPush!=stack_pop.top()){stack_push.push(*arrPush);arrPush++;}arrPush++;stack_pop.pop();}while(stack_push.size()!=0){if(stack_pop.top()!=stack_push.top()){return false;}else{stack_pop.pop();stack_push.pop();}}return true;}#endif
#include"isTheStackSeq.h"#include<iostream>int main(){int push[5]={1,2,3,4,5};int pop[5]={5,4,3,2,1};std::cout<<isStackSeq(push,pop,5);}
标签:
原文地址:http://www.cnblogs.com/yml435/p/4675045.html