Skip to content

Instantly share code, notes, and snippets.

@jmah
Created May 25, 2014 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmah/950fb8172b8cd7f857b7 to your computer and use it in GitHub Desktop.
Save jmah/950fb8172b8cd7f857b7 to your computer and use it in GitHub Desktop.
- (ListNode *)next {
if (_next) {
ListNode *nextCopy = [[ListNode alloc] init];
nextCopy.name = _next.name;
nextCopy.next = _next.next;
return nextCopy;
} else {
return nil;
}
}
- (NSUInteger)length_unsafe {
return [[self class] lengthOfListWithHead_unsafe:self count:0];
}
+ (NSUInteger)lengthOfListWithHead_unsafe:(ListNode *)node count:(NSUInteger)count {
if (!node)
return count;
else {
__unsafe_unretained ListNode *next = node.next;
return [self lengthOfListWithHead_unsafe:next count:(count + 1)];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment