Z
Z
ZelibobA17062016-10-21 18:15:44
C++ / C#
ZelibobA1706, 2016-10-21 18:15:44

Why is data not being added to the stack (STL)?

When executing the code, data is not added to sorted, I look with a debugger.

#include <stack>
using namespace std;
int main() {

    stack<int> source;
    stack<int> sorted;

    source.push(17);
    source.push(11);
    source.push(1);
    source.push(9);
    while(!source.empty())
    {
        sorted.push(10);
        source.pop();
    }
    return 0;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
romy4, 2016-10-21
@ZelibobA1706

are added)
print after source.pop();
std::cout<<"pop, stacksize"<<sorted.size()<<"\n";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question