Re: NSQueue equivalent?
Re: NSQueue equivalent?
- Subject: Re: NSQueue equivalent?
- From: mmalcolm crawford <email@hidden>
- Date: Tue, 19 Feb 2002 15:57:03 -0800
On Tuesday, February 19, 2002, at 11:32 AM, Andrew Pinski wrote:
On Tuesday, February 19, 2002, at 01:33 , Steve Mykytyn wrote:
It would be helpful to have a class like "NSQueue" that allowed one to
put in objects and take them out FIFO or LIFO. A search of the
documentation didn't reveal any obvious ways to accomplish this. Any
suggestions? Won't be that hard to write one, but would rather not
reinvent the wheel...
A class that used NSArray (CFArray) would do it.
Presumably NSMutableArray...
How about just a category thereof?
mmalc
some very old code as an example, originally used to make an
implementation easier for someone else to understand...
@implementation NSMutableArray (Stack)
/* ------------------------------------------------------------------- */
// Add an element to the stack
-(void)push:obj
{
[self addObject:obj];
}
/* ------------------------------------------------------------------- */
// Remove an element from the stack
- pop
{
id obj;
obj = [[[self top] retain] autorelease]; //return value at top of
stack
//Empty stack
returns nil
if ([self count] != 0)
[self removeLastObject];
return obj;
}
/* ------------------------------------------------------------------- */
- top
{
/*
if ([self count] == 0)
return nil;
else
return [self objectAtIndex:([self count] - 1)];
*/
return [self lastObject],
}
@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.