-
Notifications
You must be signed in to change notification settings - Fork 5
/
DKStack.m
executable file
·63 lines (50 loc) · 960 Bytes
/
DKStack.m
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// DKStack.m
//
// Feel free to use and distribute as long as you mention me. Or buy me a beer.
// Created by Dominik Krejčík on 25/09/2011.
//
#import "DKStack.h"
@implementation DKStack
-(id)init
{
if ( (self = [super init]) ) {
array = [[NSMutableArray alloc] init];
}
return self;
}
-(id)pop
{
id object = [self peek];
[array removeLastObject];
return object;
}
-(void)push:(id)element
{
[array addObject:element];
}
-(void)pushElementsFromArray:(NSArray*)arr
{
[array addObjectsFromArray:arr];
}
-(id)peek
{
return [array lastObject];
}
-(NSInteger)size
{
return [array count];
}
-(BOOL)isEmpty
{
return [array count] == 0;
}
-(void)clear
{
[array removeAllObjects];
}
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id __unsafe_unretained [])buffer count:(NSUInteger)len;
{
return [array countByEnumeratingWithState:state objects:buffer count:len];
}
@end