File tree Expand file tree Collapse file tree 3 files changed +28
-23
lines changed Expand file tree Collapse file tree 3 files changed +28
-23
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ import { MyLinkedList } from "./lfu-cache/MyLinkedList.ts";
61
61
import { level } from "./binary-tree-level-order-traversal-ii/level.ts" ;
62
62
import { inorder } from "./binary-tree-inorder-traversal/inorder.ts" ;
63
63
import { buildBST } from "./convert-sorted-list-to-binary-search-tree/buildBST.ts" ;
64
+ import { traversal_bst_range } from "./tweet-counts-per-frequency/traversal_bst_range.ts" ;
64
65
export {
65
66
TrieNode ,
66
67
TrieNodeCountWordsEqualTo ,
@@ -102,3 +103,4 @@ export { Node as MultilevelDoublyLinkedListNode } from "./flatten-a-multilevel-d
102
103
export { MyLinkedList } ;
103
104
export { level } ;
104
105
export { buildBST , inorder } ;
106
+ export { traversal_bst_range } ;
Original file line number Diff line number Diff line change 1
- import { BinarySearchTree , BinarySearchTreeNode } from "../deps.ts" ;
1
+ import { BinarySearchTree } from "../deps.ts" ;
2
+ import { traversal_bst_range } from "./traversal_bst_range.ts" ;
2
3
3
4
export default class TweetCounts {
4
5
#name_to_bst = new Map < string , BinarySearchTree < number , number > > ( ) ;
@@ -48,25 +49,3 @@ export default class TweetCounts {
48
49
return result ;
49
50
}
50
51
}
51
- export function traversal_bst_range <
52
- K extends string | number = number ,
53
- V = number ,
54
- > (
55
- node : BinarySearchTreeNode < K , V > | null | undefined ,
56
- low : number ,
57
- high : number ,
58
- callback : ( key : K , value : V ) => void ,
59
- ) {
60
- if ( ! node ) return ;
61
-
62
- const value = node . getKey ( ) ;
63
- if ( value <= high && value >= low ) {
64
- callback ( value , node . getValue ( ) ) ;
65
- }
66
- if ( value > low ) {
67
- traversal_bst_range ( node . getLeft ( ) , low , high , callback ) ;
68
- }
69
- if ( value < high ) {
70
- traversal_bst_range ( node . getRight ( ) , low , high , callback ) ;
71
- }
72
- }
Original file line number Diff line number Diff line change
1
+ import { BinarySearchTreeNode } from "../deps.ts" ;
2
+
3
+ export function traversal_bst_range <
4
+ K extends string | number = number ,
5
+ V = number ,
6
+ > (
7
+ node : BinarySearchTreeNode < K , V > | null | undefined ,
8
+ low : number ,
9
+ high : number ,
10
+ callback : ( key : K , value : V ) => void ,
11
+ ) {
12
+ if ( ! node ) return ;
13
+
14
+ const value = node . getKey ( ) ;
15
+ if ( value <= high && value >= low ) {
16
+ callback ( value , node . getValue ( ) ) ;
17
+ }
18
+ if ( value > low ) {
19
+ traversal_bst_range ( node . getLeft ( ) , low , high , callback ) ;
20
+ }
21
+ if ( value < high ) {
22
+ traversal_bst_range ( node . getRight ( ) , low , high , callback ) ;
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments