Respuesta :

Answer:

For the given input string "abcd", the permutation with an output 'd' is given by "dcba".

Explanation:

This is because for a output strings to begin with 'd', we first need to input and push characters 'a','b','c' and 'd' to stack

cin >> ch; permuteStack.push(ch); // inputs and push 'a' into the stack

cin >> ch; permuteStack.push(ch); // inputs and push 'b' into the stack

cin >> ch; permuteStack.push(ch); // inputs and push 'c' into the stack

cin >> ch; permuteStack.push(ch); // inputs and push 'd' into the stack

Then we need to pop and display character 'd' from stack to console

ch = permuteStack.pop(); cout << ch; // pops and outputs 'd' to console

After popping 'd' from stack , we can only pop the characters in the order 'c','b' and 'a'. No other popping of characters can be done, because, we have taken all the inputs and only operation which can be performed is popping and displaying.

ch = permuteStack.pop(); cout << ch; // pops and outputs 'c' to console

ch = permuteStack.pop(); cout << ch; // pops and outputs 'b' to console

ch = permuteStack.pop(); cout << ch; // pops and outputs 'a' to console

So the only permutation which can be displayed starting with 'd' is "dcba"