#import <Foundation/Foundation.h>
#import "BTreeNode.h"
BTreeNode * createBTree(int a[], int s, int t) {
if (s > t) {
return nil;
}
int m = (s + t) / 2;
BTreeNode *node = [[BTreeNode alloc] init];
node.data = a[m];
node.leftChild = createBTree(a, s, m - 1);
node.rightChild = createBTree(a, m + 1, t);
return node;
}
void visitBTree(BTreeNode *tree) {
if (tree == nil) {
return;
}
visitBTree(tree.leftChild);
printf("%d ", tree.data);
visitBTree(tree.rightChild);
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
int a[10] = {48, 50, 66, 68, 70, 75, 77, 78, 85, 88};
BTreeNode *tree = createBTree(a, 0, 9);
visitBTree(tree);
}
return 0;
}