Created
May 25, 2014 21:52
-
-
Save jmah/950fb8172b8cd7f857b7 to your computer and use it in GitHub Desktop.
This file contains 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
- (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