|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
//
// 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;
|
|
14
|
@property (nonatomic) NSUInteger lastPosition;
|
|
15
16
17
18
|
@end
@implementation Stack
|
|
19
20
21
22
23
24
25
26
|
- (id) init
{
self = [super init];
[self setLastPosition: 0];
[self setDataArray:[[NSMutableArray alloc] init]];
return self;
}
|
|
27
28
29
|
- (void) push: (id) element
{
[[self dataArray] addObject:element];
|
|
30
|
[self setLastPosition: [self lastPosition] + 1];
|
|
31
32
33
|
}
- (id) pop
{
|
|
34
|
id element;
|
|
35
|
[self setLastPosition: [self lastPosition] - 1];
|
|
36
|
element = [[self dataArray] objectAtIndex:[self lastPosition]];
|
|
37
|
[[self dataArray] removeLastObject];
|
|
38
|
return element;
|
|
39
|
}
|
|
40
|
|
|
41
42
43
44
45
46
|
- (NSInteger) count
{
return [[self dataArray] count];
}
- (void) clear
{
|
|
47
|
[[self dataArray] removeAllObjects];
|
|
48
49
50
|
}
@end
|