We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
var ary = [50, 30, 60, 15, 20, 70] var createSearchSortTree = (ary) => { let l = ary.length, Rootobj = {}, i = 0; var SearchSortTree = (ary, obj) => { if (!obj.data) { obj.data = ary[i]; if (++i < l) { SearchSortTree(ary, Rootobj) } } else if (obj.data < ary[i]) { obj.rchild ? obj.rchild : obj.rchild = {} SearchSortTree(ary, obj.rchild) } else if (obj.data > ary[i]) { obj.lchild ? obj.lchild : obj.lchild = {} SearchSortTree(ary, obj.lchild) } } SearchSortTree(ary, Rootobj) return Rootobj } var result = createSearchSortTree(ary) var searchSortTreeArray = obj => { var ary = [] var sortProcess = (obj) => { if (obj) { sortProcess(obj.lchild) ary.push(obj.data) sortProcess(obj.rchild) } } sortProcess(obj) return ary } console.log(searchSortTreeArray(result)) // [ 15, 20, 30, 50, 60, 70 ]
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: