<!-- index.html -->
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script type="text/javascript">
var list = [1, 2, 3, 4, 5, 6, 7, 8];
function make_sort_tree(arr) {
var len = arr.length,
mid = parseInt(len / 2),
node = {
value: arr[mid]
};
if(mid > 0) { node['leftChild'] = make_sort_tree(arr.slice(0, mid)); }
if(len > 2) { node['rightChild'] = make_sort_tree(arr.slice(mid + 1, len)); };
return node;
}
function serach_tree(node) {
if(node) {
var ret = [node['value']];
var leftList = serach_tree(node['leftChild']);
var rightList = serach_tree(node['rightChild']);
return leftList.concat(ret).concat(rightList);
} else {
return [];
}
}
var root = make_sort_tree(list);
console.log(root);
var ret = serach_tree(root);
console.log(ret);
</script>
</body>
</html>
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。