Spaces:
Sleeping
Sleeping
File size: 2,108 Bytes
e4bf523 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | 'use strict'
/**
* Copyright (c) 2017~2019, OBCon Inc.
* All rights reserved.
*/
/**
* @file
* @copyright 2017~2019, OBCon Inc.
* @author gye hyun james kim [pnuskgh@gmail.com]
*/
class Node {
constructor(data) {
this.data = data;
this.left = null;
this.right = null;
this.children = [];
}
}
//--- 트리 순회
//--- pre-order (선순회), post-order (후순회), in-order (중순회), level-order (단계순회)
//--- AVL Tree : 트리의 높이를 최소화
class Tree { //--- FIFO (First In First Out)
constructor(isBinaryTree=true, isAVLTree=false) {
this._root = null;
this.isBinaryTree = isBinaryTree;
this.isAVLTree = isAVLTree;
}
insert(data) {
if (this._root == null) {
this._root = new Node(data);
} else {
let cur = this._root;
//--- Reserved
}
}
remove(data) {
}
findNode(data) {
}
traversePreOrder(node) {
if (!node) {
return;
}
console.log(node.data);
for (let idx = 0; idx < node.children; idx++) {
this.traversePreOrder(node.children[idx]);
}
}
traverseInOrder(node) {
}
traversePostOrder(node) {
}
traverseLevelOrder(node) {
}
setDepthBasedOnChildren() { //--- 자식의 높이 계산
if (this.isAVLTree == false) {
return;
}
}
rotateLL() { //--- 왼쪽으로 회전
if (this.isAVLTree == false) {
return;
}
}
rotateRR() { //--- 오른쪽으로 회전
if (this.isAVLTree == false) {
return;
}
}
balance() { //--- 왼쪽/오른쪽 회전을 통해서 균형 잡기
}
}
module.exports = Tree;
|