-2
간단한 스레드 안전성을 갖는 FIFO 큐 클래스를 구현하고 싶습니다. 표준 Objective-C 프레임 워크에서 NSObject 이외의 다른 클래스를 사용하고 싶지 않습니다. NSMutableArray를 사용하고 싶지 않습니다.Objective-C FIFO 큐
내 해결책이 맞습니까? 고맙습니다!
#import <Foundation/NSObject.h>
@interface Queue : NSObject
{
id _value;
Queue *tail;
}
/* Puts an object at the end of the queue. The object is retained. */
- (void) putObject: (id)object;
/* Gets an object from the beginning of the queue. The object is
* removed from the queue. If there are no objects in the queue,
* returns nil. The object is autoreleased.
*/
- (id) getObject;
@end
@implementation Queue
- (id) init
{
return self;
}
- (void) dealloc
{
[super dealloc];
}
- (void) putObject: (id)object
{
if(tail)
{
[tail putObject:object];
}else{
tail = [[Queue alloc]init];
_object = object;
}
}
- (id) getObject
{
return _value;
}
@end
Q는 범위를 벗어났습니다. –
[질문 가이드 라인] (https://codereview.stackexchange.com/help/how-to-ask)을 읽은 후 코드 검토로 이동할 수 있습니다. –