import Foundation Foundation interface Stack NSObject property nonatom

 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
#import <Foundation/Foundation.h>
@interface Stack : NSObject
@property (nonatomanic, strong) NSMutableArray *array;
-- (id)pop;
- (void)pushObject:(id)object;
@end
@implementetion Stack
- (id)pop {
id object = [self.array objectAtIndex:0];
[self.array removeObjectAtIndex:0];
return object;
}
- (void)pushObject:(id)object {
[self.array insertObject:object atIndex:0];
}
@end
Stack stck = [Stack alloc] init];
NSArray *arr1 = @[-1, 3, -3, 5, 6];
NSArray *arr2 = [[NSArray alloc] init];
for (int i = 0; i < arr.length; i++) {
if (arr1[i] < 0) {
[self pushObject:arr1[i]];
} else {
[arr1 addObject:arr1[i]];
}
}
while (stck.array[i]) {
[arr1 addObject:[stck objectAtIndex:0]];
[stck pop];
}