Created
July 17, 2017 18:42
-
-
Save klmitchell2/63210b8a31873030d0c964a21418a084 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
- (void)depthFirstTraversal:(int)n { | |
if (n > self.count-1) { | |
NSLog(@"end of list"); | |
return; | |
} | |
if (n == 1) { | |
NSLog(@"%@", self[n]); | |
[self depthFirstTraversal:2 * n]; | |
} | |
if (n % 2 == 0) { | |
NSLog(@"%@", self[n]); | |
[self depthFirstTraversal:2 * n]; | |
} else if (n % 2 == 1) { | |
NSLog(@"%@", self[n]); | |
[self depthFirstTraversal:2 * n + 1]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment