cocoa - How do I make and use a Queue in Objective-C? -
I want to use a queue data structure in my objective program. In C ++, I used the STL queue, what is the equivalent data structure in Objective-C? How can I pop / pop the item?
Ben's version is a stack rather than a line, so I'm a little bit:
NSMutableArray + QueueAdditions.h
@interface NSMutableArray (QEdition) - dequeue (ID); - (zero) enqueue: (id) obz; @end NSMutableArray + queueAdditions.m
@implementation NSMutableArray (QueueAdditions) // queues are first-in-first Generally, we remove the object from the head- (id) dequ {// if ([self calculation] == 0) return zero; // Avoid exceptions (Quinn) ID head objects = [auto-objectattackedx: 0]; If (headObject! = Zero) {[headObject retain] autorelease]; // So it is not dealloc'ed on removing [self-removal objectOtindex: 0]; } Return head object; } // Add on the queue tail (when people cut the line, no one likes it!) - (zero) enqueue: (id) an object {[self adjective: an object]; // This method automatically combines at the end of the array) @ and Just want to use your new methods, and you want to call them like any other NSMutableArray methods.
Put on good luck and coating!
Comments
Post a Comment