-2
は、私は、単純なスレッドセーフを持つFIFOキュークラスを実装したいです。私は標準のObjective-Cフレームワークからどんなクラス(NSObject以外)も使いたいとは思っていません。つまり、NSMutableArrayを使いたくないということです。Objective-CのFIFOキュー
私の解決策が正しければ、あなたがSEできますか?ありがとうございました!
#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はSOの範囲外です。 –
あなたが彼らの[質問ガイドライン](https://codereview.stackexchange.com/help/how-to-ask)を読んだ後、あなたはコードレビューにこれを移動する場合があります。 –