Question On Stack Permutation
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 se开发者_如何学JAVAen 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.
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.
精彩评论