Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / January 2006



Tip: Looking for answers? Try searching our database.

Simple stack class

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew Ebling - 28 Jan 2006 16:43 GMT
Today I found I needed a really simple stack class to solve an
Objective-C programming problem elegantly.  Being a newbie, I headed
straight for the documentation, but couldn't find anything suitable.

Do I really have to go and implement my own stack class from scratch or
is it just called something else in the Foundation Kit?

thanks,

Andy
Michael Ash - 28 Jan 2006 17:53 GMT
> Today I found I needed a really simple stack class to solve an
> Objective-C programming problem elegantly.  Being a newbie, I headed
> straight for the documentation, but couldn't find anything suitable.
>
> Do I really have to go and implement my own stack class from scratch or
> is it just called something else in the Foundation Kit?

Use an NSMutableArray. push = addObject:, peek = lastObject, pop =
removeLastObject. Be careful about memory management when popping, as the
object you get from lastObject could be destroyed when you call
removeLastObject, so you should retain and autorelease it first. For
maximum convenience, put these methods in a category so you don't have to
go through this manually every time you want to pop something.

Signature

Michael Ash
Rogue Amoeba Software

Peter Ammon - 29 Jan 2006 22:01 GMT
> Today I found I needed a really simple stack class to solve an
> Objective-C programming problem elegantly.  Being a newbie, I headed
[quoted text clipped - 6 lines]
>
> Andy

Unlike some other platforms, Cocoa provides only three generic data
structures - array, set, and dictionary.  But the implementations are
polymorphic, so an array will work fine as a stack.

-Peter

Signature

Pull out a splinter to reply.

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.