Created
April 28, 2018 20:52
-
-
Save soapyigu/c62eaf911c4482f6e13203f1c7e0b3ea to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@interface Queue() | |
@property (nonatomic, strong) NSMutableArray<id> *array; | |
@end | |
@implementation Queue | |
- (instancetype)init { | |
self = [super init]; | |
if (self) { | |
_array = [[NSMutableArray alloc] init]; | |
} | |
return self; | |
} | |
- (void)enqueue:(id)value { | |
[self.array addObject:value]; | |
} | |
- (id)dequeue { | |
if (self.array.count > 0) { | |
id value = _array[0]; | |
[self.array removeObjectAtIndex:0]; | |
return value; | |
} | |
return nil; | |
} | |
- (NSString *)description { | |
return [NSString stringWithFormat:@"The queue is [%@]", self.array]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment