Created
September 18, 2012 08:16
-
-
Save jlcampana/3741977 to your computer and use it in GitHub Desktop.
NSMutableArray+Stack.m
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
// | |
// NSMutableArray+Stack.m | |
// shell poc | |
// | |
// Created by Jose Luis Campaña on 9/18/12. | |
// Copyright (c) 2012 Jose Luis Campaña. All rights reserved. | |
// | |
#import "NSMutableArray+Stack.h" | |
@implementation NSMutableArray (Stack) | |
- (void) push: (id)item { | |
[self addObject:item]; | |
} | |
- (id) pop | |
{ | |
id item = nil; | |
if ([self count] != 0) | |
{ | |
item = [self lastObject] ; | |
[self removeLastObject]; | |
} | |
return item; | |
} | |
- (id) peek { | |
id item = nil; | |
if ([self count] != 0) { | |
item = [self lastObject]; | |
} | |
return item; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment