Skip to content

Commit

Permalink
feat: TreeNode 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
toothlessdev committed Aug 28, 2024
1 parent 844eff0 commit 70b9de0
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/services/BallGameRoot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { TreeNode } from "./TreeNode";

export const BallGameRoot = new TreeNode.Builder("구기/비구기")
.setLeft(
new TreeNode.Builder("역시 체육은 공놀이지")
.setLeft(
new TreeNode.Builder("운동은 좀 복작복작 해야지")
.setLeft(
new TreeNode.Builder("좀 부딪히는게 재밌지")
.setValue(["센토", "맨투맨", "동그라미", "오렌지파이터스"])
.build(),
)
.setRight(
new TreeNode.Builder("내 몸에 손대지 마!!")
.setValue(["스트라이크", "파란", "스파이크"])
.build(),
)
.build(),
)
.setRight(
new TreeNode.Builder("꼭 사람이 많을 필요는 없지")
.setLeft(
new TreeNode.Builder("내 눈을 바라봐. 난 당신 얼굴이 궁금하다.")
.setValue(["KUTC", "스매싱", "스윙스"])
.build(),
)
.setRight(new TreeNode.Builder("난 앞만 봐.").setValue(["KGA", "KNUBC"]).build())
.build(),
)
.build(),
)
.setRight(
new TreeNode.Builder("응 아니야~")
.setLeft(new TreeNode.Builder("장비 따위 필요 없어. 최고의 장비는 바로 나!").build())
.setRight(new TreeNode.Builder("인간은 도구를 사용해야지!").build())
.build(),
)
.build();
43 changes: 43 additions & 0 deletions src/services/TreeNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export class TreeNode {
left: TreeNode | null;
right: TreeNode | null;
value: any;

constructor(value: any) {
this.left = null;
this.right = null;
this.value = value;
}
set setLeft(node: TreeNode) {
this.left = node;
}
set setRight(node: TreeNode) {
this.right = node;
}
get getValue() {
return this.value;
}

static Builder = class Builder {
private node: TreeNode;

constructor(value: any) {
this.node = new TreeNode(value);
}
setLeft(node: TreeNode): this {
this.node.left = node;
return this;
}
setRight(node: TreeNode): this {
this.node.right = node;
return this;
}
setValue(value: any): this {
this.node.value = value;
return this;
}
build(): TreeNode {
return this.node;
}
};
}

0 comments on commit 70b9de0

Please sign in to comment.