: suppose the input to a stack is 1,2,3,4,5 in the order, i.e., 1
: comes first,then 2 and so on. Which of the following rearrangements
: can be obtained in the output order? for those that can, explain
: how, giving the sequence of operations. for those outputs that
: cannot be so obtained, explaing why.
: 1) 1 2 4 5 3
: 2) 2 1 4 3 5
: 3) 2 1 5 3 4
: 4) 3 1 2 4 5
Well, one can obtain any of these, when needed:
//Creates the std::stack as described
const std::stack<int> s = CreateStack();
//Copy it to a std::vector
const std::vector<int> v(s);
//Shuffle it!
std::random_shuffle(v.begin(),v.end());