是否正确

oral_quiz->#IsPopOrder#

[亡魂溺海] 提交于 2020-12-05 22:07:14
#include <stdio.h> #include <stack> #include <exception> bool MyIsPopOrder(int* InSeq, int* OutSeq, int length) { if(InSeq == NULL || OutSeq == NULL || length <= 0) return false; std::stack<int> stackAid; int index = 0; for(int i=0; i<length; ++i) { if(!stackAid.empty() && OutSeq[i] == stackAid.top()) { stackAid.pop(); continue; } while(index < length && InSeq[index] != OutSeq[i]) { stackAid.push(InSeq[index++]); } //push if(index < length && InSeq[index] == OutSeq[i]) stackAid.push(InSeq[index]); if(!stackAid.empty() && OutSeq[i] != stackAid.top() && index >= length) return false; //pop if