Blame view

DUREX tests/Stack.m 828 Bytes
Imanol-Mikel Barba Sabariego authored
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;
Imanol-Mikel Barba Sabariego authored
14
@property (nonatomic) NSUInteger lastPosition;
Imanol-Mikel Barba Sabariego authored
15
16
17
18
@end

@implementation Stack
Imanol-Mikel Barba Sabariego authored
19
20
21
22
23
24
25
26
- (id) init
{
    self = [super init];
    [self setLastPosition: 0];
    [self setDataArray:[[NSMutableArray alloc] init]];
    return self;
}
Imanol-Mikel Barba Sabariego authored
27
28
29
- (void) push: (id) element
{
    [[self dataArray] addObject:element];
Imanol-Mikel Barba Sabariego authored
30
    printf("%d elements in array\n",[self count]);
Imanol-Mikel Barba Sabariego authored
31
32
33
}
- (id) pop
{
Imanol-Mikel Barba Sabariego authored
34
35
    id element;
    element  = [[self dataArray] objectAtIndex:[self lastPosition]];
Imanol-Mikel Barba Sabariego authored
36
    [[self dataArray] removeLastObject];
Imanol-Mikel Barba Sabariego authored
37
    return element;
Imanol-Mikel Barba Sabariego authored
38
39
40
41
42
43
44
45
46
47
48
}
- (NSInteger) count
{
    return [[self dataArray] count];
}
- (void) clear
{

}

@end