//
//  Stack.m
//  DUREX test
//
//  Created by Imanol Barba on 5/23/14.
//  Copyright (c) 2014 Emmoco. All rights reserved.retur
//

#import "Stack.h"

@interface Stack ()

@property (strong,nonatomic) NSMutableArray *dataArray;
@property (nonatomic) NSUInteger lastPosition;
@end

@implementation Stack

- (id) init
{
    self = [super init];
    [self setLastPosition: 0];
    [self setDataArray:[[NSMutableArray alloc] init]];
    return self;
}

- (void) push : (id) element
{
    [[self dataArray] addObject:element];
    [self setLastPosition: [self lastPosition] + 1];
}
- (id) pop
{
    id element;
    [self setLastPosition: [self lastPosition] - 1];
    element  = [[self dataArray] objectAtIndex:[self lastPosition]];
    [[self dataArray] removeLastObject];
    return element;
}
- (NSInteger) count
{
    return [[self dataArray] count];
}
- (void) clear
{
    [[self dataArray] removeAllObjects];
}

@end
