Skip to content

Instantly share code, notes, and snippets.

@ejamesc
Created January 27, 2013 15:57
Show Gist options
  • Select an option

  • Save ejamesc/4648970 to your computer and use it in GitHub Desktop.

Select an option

Save ejamesc/4648970 to your computer and use it in GitHub Desktop.
-(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