Created
November 14, 2015 08:48
-
-
Save ardarda/3353970683efc61b3952 to your computer and use it in GitHub Desktop.
StdQueue Obj.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface StdQueue : NSObject | |
@property(nonatomic, readonly) BOOL empty; | |
@property(nonatomic, readonly) NSUInteger size; | |
@property(nonatomic, readonly) id front; | |
@property(nonatomic, readonly) id back; | |
- (void)enqueue:(id)object; | |
- (id)dequeue; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "StdQueue.h" | |
@interface StdQueue () | |
@property(nonatomic, strong) NSMutableArray* storage; | |
@end | |
@implementation StdQueue | |
#pragma mark NSObject | |
- (id)init | |
{ | |
if (self = [super init]) { | |
_storage = [NSMutableArray array]; | |
} | |
return self; | |
} | |
#pragma mark StdQueue | |
- (BOOL)empty | |
{ | |
return self.storage.count == 0; | |
} | |
- (NSUInteger)size | |
{ | |
return self.storage.count; | |
} | |
- (id)front | |
{ | |
return self.storage.firstObject; | |
} | |
- (id)back | |
{ | |
return self.storage.lastObject; | |
} | |
- (void)enqueue:(id)object | |
{ | |
[self.storage addObject:object]; | |
} | |
- (id)dequeue | |
{ | |
id firstObject = nil; | |
if (!self.empty) { | |
firstObject = self.storage.firstObject; | |
[self.storage removeObjectAtIndex:0]; | |
} | |
return firstObject; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment