Created
January 27, 2013 15:57
-
-
Save ejamesc/4648970 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -(id)initWithTerms:(NSArray*)ts{ // 5 points | |
| // REQUIRES: "ts" satisfies clauses given in the representation invariant | |
| // EFFECTS: constructs a new polynomial using "ts" as part of the representation. | |
| // the method does not make a copy of "ts". remember to call checkRep to check for representation invariant | |
| if (self = [super init]) { | |
| terms = [ts sortedArrayUsingComparator:^NSComparisonResult(id a, id b) { | |
| // RatTerm has a property expt that is an int | |
| int first = [(RatTerm*)a expt]; | |
| int second = [(RatTerm*)b expt]; | |
| if (first > second) return NSOrderedAscending; | |
| else if (first < second) return NSOrderedDescending; | |
| else return NSOrderedSame; | |
| }]; | |
| [self checkRep]; | |
| return self; | |
| } else return nil; | |
| return self; | |
| } | |
| // Error message [__NSArrayI objCType]: unrecognized selector sent to instance 0x102f92b70 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment