We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2174cd3 commit e57c1f3Copy full SHA for e57c1f3
1 file changed
frontend/src/app/tree.ts
@@ -0,0 +1,31 @@
1
+
2
+interface TreeNode<T> {
3
+ value: T;
4
+ children: TreeNode<T>[];
5
+}
6
7
+class Tree<T> {
8
+ _root?: TreeNode<T>;
9
10
+ get root(): TreeNode<T> {
11
+ if (!this._root) {
12
+ throw new Error("Tree is empty")
13
+ }
14
+ return this._root;
15
16
17
+ constructor(root?: TreeNode<T>) {
18
+ this._root = root;
19
20
21
+ static empty<T>(): Tree<T> {
22
+ return new Tree();
23
24
25
+ static fromJSON<T>(json: any): Tree<T> {
26
+ // there's no validation of the content
27
+ return new Tree(json);
28
29
30
31
+export {Tree, TreeNode};
0 commit comments