Skip to content

Instantly share code, notes, and snippets.

@MaxGabriel
Created February 16, 2012 21:07
Show Gist options
  • Save MaxGabriel/1847858 to your computer and use it in GitHub Desktop.
Save MaxGabriel/1847858 to your computer and use it in GitHub Desktop.
CS193p Fall 2011 Assignment 2--Calculator
//Iterates through program, an array of operations and NSNumbers
//Returns human-readable list of numbers and operations in RPN
+ (NSString *)descriptionOfProgram:(id)program
{
NSString *description = [[NSString alloc] init];
if ([program isKindOfClass:[NSArray class]]) {
for (int i=0; i<[program count]; i++) {
if ([[program objectAtIndex:i] isKindOfClass:[NSNumber class]]) {
description = [description stringByAppendingString:[[program objectAtIndex:i] stringValue]];
} else {
description = [description stringByAppendingFormat:@"%@",[program objectAtIndex:i]];
}
description = [description stringByAppendingString:@" "];
}
}
return description;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment