Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!emory!ogicse!unmvax!uokmax!corona!ptgarvin From: ptgarvin@corona.ecn.uoknor.edu (PTed Garvin) Newsgroups: comp.lang.c Subject: Re: Alphabetizing stacks Message-ID: <1991Apr22.003454.18014@uokmax.ecn.uoknor.edu> Date: 22 Apr 91 00:34:54 GMT References: <1991Apr21.121232.2659@jack.sns.com> Sender: news@uokmax.ecn.uoknor.edu (Nets) Organization: Discordian Information Production and Distribution, Ltd Lines: 24 In article <1991Apr21.121232.2659@jack.sns.com> jtanner@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@aardvark.ucs.uoknor.edu / ptgarvin@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. ___|___