本文整理汇总了C++中MyStack::pop方法的典型用法代码示例。如果您正苦于以下问题:C++ MyStack::pop方法的具体用法?C++ MyStack::pop怎么用?C++ MyStack::pop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyStack
的用法示例。
在下文中一共展示了MyStack::pop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
cout<<"----------MyStack<int>---------------"<<endl;
MyStack<int> mysatck;
mysatck.push(1);
mysatck.push(2);
mysatck.push(3);
cout<<mysatck.pop()<<endl;
cout<<mysatck.pop()<<endl;
cout<<mysatck.pop()<<endl;
cout<<"----------deque<int>---------------"<<endl;
deque<int> dequeint;
dequeint.push_front(1);
dequeint.push_front(2);
dequeint.push_front(3);
cout<<dequeint.front()<<endl;
dequeint.pop_front();
cout<<dequeint.front()<<endl;
dequeint.pop_front();
cout<<dequeint.front()<<endl;
dequeint.pop_front();
return 0;
}
示例2: uTest
bool uTest( UnitTest *utest_p)
{
bool thrown_error = false;
//Tested instance
MyStack stack;
stack.push(1);
stack.push(2);
UTEST_CHECK( utest_p, stack.size() == 2);
int second = stack.pop();
int first = stack.pop();
UTEST_CHECK( utest_p, second == 2);
UTEST_CHECK( utest_p, first == 1);
UTEST_CHECK( utest_p, stack.size() == 0);
try
{
stack.pop();
} catch ( MyStack::Error)
{
thrown_error = true;
}
UTEST_CHECK( utest_p, thrown_error);
return utest_p->result();
}
示例3: main
int main(void)
{
MyStack<char> *pStack = new MyStack<char>(20);
MyStack<char> *pNeedStack = new MyStack<char>(20);
char str[] = "[[]>]]";
char isNeeded = 0;
cout << strlen(str) << endl;
for (int i = 0; i < strlen(str); i++)
{
cout << str[i] << endl;
if (str[i] != isNeeded)
{
pStack->push(str[i]);
cout << "push stack: " << str[i] << endl;
switch(str[i]) {
case '[':
if (0 != isNeeded) {
pNeedStack->push(isNeeded);
cout << "push isNeeded: " << isNeeded << endl;
}
isNeeded = ']';
break;
case '(':
if (0 != isNeeded) {
pNeedStack->push(isNeeded);
cout << "push isNeeded: " << isNeeded << endl;
}
isNeeded = ')';
break;
default:
cout << "string is not matched." << endl;
return 0;
break;
}
} else {
char temp = 0;
pStack->pop(temp);
cout << "pop stack: " << temp << endl;
if (!pNeedStack->pop(isNeeded)) {
isNeeded = 0;
}
cout << "pop isNeeded: " << isNeeded << endl;
}
}
if (pStack->stackEmpty()) {
cout << "string is matched" << endl;
} else {
cout << "string is not matched" << endl;
}
delete pStack;
pStack = NULL;
delete pNeedStack;
pNeedStack = NULL;
return 0;
}
示例4: pop
int pop() {
while(!S1.isEmpty())
S2.push(S1.pop());
temp = S2.pop();
while(!S2.isEmpty())
S1.push(S2.pop());
return temp;
}
示例5: checkvp
void Expression::checkvp()
{
stk = new MyStack(exp.length());
for (int i = 0; i < exp.length(); ++i)
{
if (exp.at(i) == '{' || exp.at(i) == '(' || exp.at(i) == '[')
{
stk->push(exp.at(i));
}
else if (exp.at(i) == '}' || exp.at(i) == ')' || exp.at(i) == ']')
{
if (exp.at(i) == '}')
{
char c = stk->get_top();
if (c == '{')
{
stk->pop(exp.at(i));
}
else
{
cout << "Not well parenthesized!\n"
return;
}
}
if (exp.at(i) == ')')
{
char c = stk->get_top();
if (c == '(')
{
stk->pop(exp.at(i));
}
else
{
cout << "Not well parenthesized!\n"
return;
}
}
if (exp.at(i) == ']')
{
char c = stk->get_top();
if (c == '[')
{
stk->pop(exp.at(i));
}
else
{
cout << "Not well parenthesized!\n"
return;
}
}
示例6: twoNumsProcess
/* Function: twoNumsProcess()
* Usage: is called by sortTokenByStacks() or getFinalStacksResult() functions
* -----------------------------------------------------------------------------------------//
* Makes single calculation for two top numbers in stack, and return result to
* stackNumbers back.
*
*
* @param stackNumbers Stack of number values for current recursion
* @param stackOperators Stack of operators for current recursion */
void twoNumsProcess(MyStack<double> &stackNumbers, MyStack<string> &stackOperators) {
/* Stacks elements validation checking for calculating process */
if((stackNumbers.size() - stackOperators.size()) != 1) {
cout << " - CHECK YOUR INPUT, NOT ENOUGH NUMBERS IN FORMULA!" << endl;
failFlag = true;
} else {
/* Calculating process */
double num2 = stackNumbers.pop();
double num1 = stackNumbers.pop();
string thisOper = stackOperators.pop();
double result = singleCalculation(num1, thisOper, num2);
stackNumbers.push(result);
}
}
示例7: processChar
void processChar( char item, MyStack<Token> &stack, string &operations, bool &OK )
{
// Note:
// I could check top of stack before adding tokens
// and catch many errors "now" instead of later.
// I'd rather be lazy and let collapse() catch the errors.
Token token = toToken(item);
switch (token)
{
case TOKEN_VALUE:
if ( stack.isEmpty() ) { stack << token; return; }
switch ( stack.top() )
{
case TOKEN_LEFT_GROUP: stack << token; break;
case TOKEN_ADDITION: stack << token; break; // don't collapse yet
case TOKEN_MULTIPLICATION: collapse( stack << token, operations, OK ); break;
default: OK = false; break;
}
break;
case TOKEN_ADDITION:
collapse( stack, operations, OK);
stack << TOKEN_ADDITION;
break;
case TOKEN_MULTIPLICATION:
case TOKEN_LEFT_GROUP:
stack << token;
break;
case TOKEN_RIGHT_GROUP:
// clear any pending addidion
collapse( stack, operations, OK );
if ( !OK ) return;
// convert ( value ) to value
if ( !stack.isEmpty() && TOKEN_VALUE == stack.pop()
&& !stack.isEmpty() && TOKEN_LEFT_GROUP == stack.pop() )
stack << TOKEN_VALUE;
else
OK = false;
break;
case TOKEN_UNKNOWN:
OK = false;
break;
}
}
示例8: string_test
void string_test()
{
string next;
char c;
MyStack<string> s;
cout << "Enter a sentence or two\n";
// read from terminal word by word
while (cin >> next) {
// put latest word into stack
s.push(next);
// was that the last word on the line?
c = cin.get();
if (c == '\n')
break;
else
cin.putback(c);
}
cout << "Written backward that is:\n";
while (!s.empty())
cout << s.pop() << " ";
cout << "\n";
}
示例9: test_qa
void test_qa(AnsType& expectAns, OpreateType& opreateParam, InitType& initData, DataType1 firstData = DataType1()) {
AnsType ans;
MyStack work;
for(int i=0; i<opreateParam.size(); i++) {
int ansTmp = -1;
if(opreateParam[i] == "push") {
work.push(firstData[i]);
}
if(opreateParam[i] == "pop") {
ansTmp = work.pop();
}
if(opreateParam[i] == "top") {
ansTmp = work.top();
}
if(opreateParam[i] == "empty") {
ansTmp = work.empty();
}
ans.push_back(ansTmp);
}
int index = getIndex();
bool check = eq(ans, expectAns);
if(!check) {
printf("index %d: NO\n", index);
output("opreateParam", opreateParam);
output("initData", initData);
output("firstData", firstData);
output("ans", ans);
output("expectAns", expectAns);
} else {
printf("index %d: YES\n", index);
}
printf("\n");
}
示例10: main
//Driver code
int main()
{
MyStack s;
s.push(3);
s.push(5);
s.getMin();
s.push(2);
s.push(1);
s.getMin();
s.pop();
s.getMin();
s.pop();
s.peek();
return 0;
}
示例11: solveMas
bool solveMas(string s)
{
MyStack<char> st;
char skob[3][2];
skob[0][0] = '(';
skob[1][0] = '[';
skob[2][0] = '{';
skob[0][1] = ')';
skob[1][1] = ']';
skob[2][1] = '}';
for (int i = 0 ; i < s.size() ; i++) {
char c = s[i];
int curJ = -1, curK;
for (int j = 0 ; j < 3 ; j++) {
for (int k = 0 ; k < 2 ; k++) {
if (skob[j][k] == c) {
curJ = j, curK = k;
break;
}
}
if (curJ != -1)
break;
}
if (curK == 1) {
if (!st.sz || st.front() != skob[curJ][0]) {
return false;
}
st.pop();
} else {
st.push(c);
}
}
return !st.sz;
}
示例12: main
int main (void)
{
MyStack *pStack = new MyStack(5);
pStack->push('a');
pStack->push('e');
pStack->push('i');
pStack->push('o');
pStack->push('u');
//pStack->clearStack();
pStack->stackTraverse(true);
char elem = 0;
pStack->pop(elem);
cout << elem << endl;
pStack->stackTraverse(true);
cout << pStack -> stackLength() << endl;
if(pStack->stackEmpty()){
cout << "栈为空" << endl;
}
if(pStack->stackFull()){
cout << "栈为满" << endl;
}
delete pStack;
pStack = NULL;
return 0;
}
示例13: char_test
void char_test()
{
char next;
MyStack<char> s;
cout << "Enter some text\n";
// read characters in one by one until newline reached
cin.get(next);
while (next != '\n') {
// push latest character
s.push(next);
cin.get(next);
}
cout << "Written backward that is:\n";
// output all characters stored in stack
while (!s.empty())
cout << s.pop();
cout << "\n";
}
示例14: PreTraverse
//先序
void MyTree::PreTraverse(TreeNode* pNode)
{
// if(pNode == NULL)
// {
// return;
// }
//
// printf("%d ", pNode->m_Data);
// PreTraverse(pNode->m_pLeft);
// PreTraverse(pNode->m_pRight);
MyStack<TreeNode*> ss;
TreeNode* pCur = pNode;
do
{
while(pCur)
{
printf("%d ", pCur->m_Data);
ss.push(pCur);
pCur = pCur->m_pLeft;
}
if(!ss.IsEmpty())
{
pCur = ss.pop();
pCur = pCur->m_pRight;
}
}while(pCur || !ss.IsEmpty());
}
示例15: sortStack
// 追加スタック数2
MyStack sortStack(MyStack stack) {
MyStack ans(10), tmp(10);
// 最小値を見つける
while (!stack.isEmpty()) {
int min = stack.peek();
while (!stack.isEmpty()) {
int t = stack.peek();
stack.pop();
if (t <= min) {
min = t;
}
tmp.push(t);
}
// 最小値を入れる
while (!tmp.isEmpty()) {
if (tmp.peek() == min) {
ans.push(tmp.peek());
} else {
stack.push(tmp.peek());
}
tmp.pop();
}
}
return ans;
}