Reputation: 4197
I want to ask that is it necessary that first number in stack permutation should be 1 and last should be n(last number in queue). The examples on web I have seen all have first element 1 and last as n. But using stack permutation algo we can get any number on first place and any on last place.
Upvotes: 0
Views: 193
Reputation: 32504
Permuting a stack should give you a stack which is isomorphic to the original and so the starting state is mostly irrelevant and you could just relabel it as { 1, 2, 3 ... n } so yes, you could start at any number and end at any other.
The web has it from 1 through N because that makes it easier to explain.
Upvotes: 2