it's not always possible to sort a stack in all the cases , consider the stack 2143 and one tries to sort it feeding the elements in order , we have now ....whatever popping technique we use , we cannot have a 1234 kind of stack in order .The maximum number of permutations we can have with a stack is 2nCn -2nCn-1 which does not necessarily include the permutated group . In general , we can pop the elements in a decreasing order in the same order as they are entered . Try sortin the stack with an input of 4132 .now possible
On Sun, Jun 13, 2010 at 1:57 PM, jaladhi dave <jaladhi.k.d...@gmail.com>wrote: > what do you mean by sorting elements in stack ? A stack is a data > structure in which the relative position of elements depend on their order > of insertion. > > If we sort elements in stack, how does it retain the property of a stack ? > > If we really want that property, we will have O(n) rather than O(1) insert > and maintain two pointers. Stack next and sorted next. > > > On Sun, Jun 13, 2010 at 1:05 PM, jalaj jaiswal > <jalaj.jaiswa...@gmail.com>wrote: > >> how to sort elements of stack using constant space >> >> -- >> With Regards, >> >> +919026283397 >> B.TECH IT >> IIIT ALLAHABAD >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algoge...@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> >> . >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.