Blame view

BT Vendor/Stack.m 920 Bytes
Imanol-Mikel Barba Sabariego authored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//
//  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;
}
Imanol-Mikel Barba Sabariego authored
27
- (void) push : (id) element
Imanol-Mikel Barba Sabariego authored
28
29
{
    [[self dataArray] addObject:element];
Imanol-Mikel Barba Sabariego authored
30
    [self setLastPosition: [self lastPosition] + 1];
Imanol-Mikel Barba Sabariego authored
31
32
33
34
}
- (id) pop
{
    id element;
Imanol-Mikel Barba Sabariego authored
35
    [self setLastPosition: [self lastPosition] - 1];
Imanol-Mikel Barba Sabariego authored
36
37
38
39
40
41
42
43
44
45
    element  = [[self dataArray] objectAtIndex:[self lastPosition]];
    [[self dataArray] removeLastObject];
    return element;
}
- (NSInteger) count
{
    return [[self dataArray] count];
}
- (void) clear
{
Imanol-Mikel Barba Sabariego authored
46
    [[self dataArray] removeAllObjects];
Imanol-Mikel Barba Sabariego authored
47
48
49
}

@end