Skip to content

Instantly share code, notes, and snippets.

@soapyigu
Created April 28, 2018 20:52
Show Gist options
  • Save soapyigu/c62eaf911c4482f6e13203f1c7e0b3ea to your computer and use it in GitHub Desktop.
Save soapyigu/c62eaf911c4482f6e13203f1c7e0b3ea to your computer and use it in GitHub Desktop.
@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