Skip to content

Instantly share code, notes, and snippets.

@jlcampana
Created September 18, 2012 08:16
Show Gist options
  • Save jlcampana/3741977 to your computer and use it in GitHub Desktop.
Save jlcampana/3741977 to your computer and use it in GitHub Desktop.
NSMutableArray+Stack.m
//
// 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