Skip to content

Instantly share code, notes, and snippets.

@klmitchell2
Created July 17, 2017 18:42
Show Gist options
  • Save klmitchell2/63210b8a31873030d0c964a21418a084 to your computer and use it in GitHub Desktop.
Save klmitchell2/63210b8a31873030d0c964a21418a084 to your computer and use it in GitHub Desktop.
- (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