Alphabetizing stacks

PTed Garvin ptgarvin at corona.ecn.uoknor.edu
Mon Apr 22 10:34:54 AEST 1991


In article <1991Apr21.121232.2659 at jack.sns.com> jtanner at jack.sns.com (Jason Tanner) writes:
>
[wants to alphabetize a Stack]

Are you wanting to use any other data structures?  Have you ever heard of the
"Towers of Hanoi" problem?  Essentially, that is an alphabetization 
problem, where one wants to have the disks ordered from largest to smallest.

I'd pop all the items off the stack, put them in an array, alphabetize
the array, then push them all back.  Sounds nasty, especially if you do
this every time you push.  If an alphabetized list is important, a stack
might not be the best data structure (assuming you only access one end).
Perhaps some form of bastard stack, where you can insert in the middle,
but remove only from the top.  (Insertion sort).

I refer you to book on Data Structures.



--
"...just when I had you wriggling in the crushing grip of reason, too..."
ptgarvin at aardvark.ucs.uoknor.edu / ptgarvin at uokmax.UUCP | Wassail!        O  
in the Society: Padraig Cosfhota o Ulad / Barony of Namron, Ansteorra     |  
Disclaimer: Fragile. Contents inflammable. Do not use near open flame. ___|___



More information about the Comp.lang.c mailing list