Skip to content

Commit 84bf1a5

Browse files
committed
测试
1 parent 57046af commit 84bf1a5

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

finding-mk-average/MultiRedBlackTree.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,15 @@ export class MultiRedBlackTree<T> extends RedBlackTreeExtended<T> {
3636
insertGetNode(value: T): MultiRedBlackNode<T> | null {
3737
let node = this.insertNode(
3838
MultiRedBlackNode,
39-
value,
39+
value
4040
) as MultiRedBlackNode<T> | null;
4141
if (node) {
4242
while (node.parent?.red) {
4343
let parent: MultiRedBlackNode<T> = node.parent!;
44-
const parentDirection: Direction = parent
45-
.directionFromParent()!;
46-
const uncleDirection: Direction = parentDirection === "right"
47-
? "left"
48-
: "right";
44+
const parentDirection: Direction =
45+
parent.directionFromParent()!;
46+
const uncleDirection: Direction =
47+
parentDirection === "right" ? "left" : "right";
4948
const uncle: MultiRedBlackNode<T> | null =
5049
parent.parent![uncleDirection] ?? null;
5150

finding-mk-average/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,18 @@ class MKAverage {
2020
if (this.queue.length === this.m) {
2121
const willBeDelete: number = this.queue[0];
2222
this.queue.shift();
23-
23+
console.log("deleteElement", willBeDelete);
2424
this.total -= willBeDelete;
2525
this.tree.remove(willBeDelete);
26+
const root = this.tree.getRoot();
27+
if (!root) throw Error("null root");
28+
{
29+
const temp: [number, number][] = [];
30+
for (const node of InOrderIterator(root)) {
31+
temp.push([node.value, node.count]);
32+
}
33+
console.log(JSON.stringify(temp));
34+
}
2635
}
2736

2837
this.queue.push(num);
@@ -31,6 +40,7 @@ class MKAverage {
3140
this.total += num;
3241
this.count++;
3342
// debugger;
43+
console.log("addElement", num);
3444
const root = this.tree.getRoot();
3545
if (!root) throw Error("null root");
3646
{
@@ -48,14 +58,14 @@ class MKAverage {
4858
let ret = this.total;
4959
const root = this.tree.getRoot();
5060
if (!root) throw Error("null root");
61+
console.log("calculateMKAverage");
5162
{
5263
const temp: [number, number][] = [];
5364
for (const node of InOrderIterator(root)) {
5465
temp.push([node.value, node.count]);
5566
}
5667
console.log(JSON.stringify(temp));
5768
}
58-
5969

6070
// console.log(root)
6171
let k = this.k;

0 commit comments

Comments
 (0)