Created
March 20, 2015 04:10
-
-
Save kmdarshan/1d82494978d298e8cd1e to your computer and use it in GitHub Desktop.
Queue in objective 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
// | |
// RRQueue.h | |
// learnObjectiveC | |
// | |
// Created by darshan on 3/19/15. | |
// Copyright (c) 2015 Happy Days. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface RRQueue : NSObject | |
-(BOOL) isEmpty; | |
-(void) enQueue:(NSObject*)object; | |
-(NSObject*) deQueue; | |
@end | |
// | |
// RRQueue.m | |
// learnObjectiveC | |
// | |
// Created by darshan on 3/19/15. | |
// Copyright (c) 2015 Happy Days. All rights reserved. | |
// | |
#import "RRQueue.h" | |
@interface RRQueue() | |
@property (nonatomic, strong) NSMutableArray *array; | |
@end | |
@implementation RRQueue | |
-(id) init { | |
if (self) { | |
// initialize this for maintaining the queue | |
self.array = [NSMutableArray new]; | |
} | |
return self; | |
} | |
-(BOOL)isEmpty { | |
if ([self.array count] > 0) { | |
return NO; | |
} | |
return YES; | |
} | |
-(void)enQueue:(NSObject *)object { | |
[self.array addObject:object]; | |
} | |
-(NSObject *)deQueue { | |
if ([self.array count] > 0) { | |
NSObject *firstObject = [self.array firstObject]; | |
[self.array removeObjectAtIndex:0]; | |
return firstObject; | |
} | |
return nil; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment