Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -(NSMutableArray *)operandStack // override the getter for lazy instantiation
- {
- if (!_operandStack)
- {
- [self setOperandStack:[[NSMutableArray alloc] init]];
- }
- return _operandStack;
- }
- -(void)pushOperand:(double)operand
- {
- NSNumber *operandObject = [NSNumber numberWithDouble:operand];
- [[self operandStack] addObject:operandObject];
- }
- -(double)popOperand
- {
- NSNumber *operandObject = [[self operandStack] lastObject];
- if (operandObject)
- {
- [[self operandStack] removeLastObject];
- return [operandObject doubleValue];
- }
- else
- {
- return 0;
- }
- }
Add Comment
Please, Sign In to add comment