File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change 1
1
import { reverseInOrderIterator } from "../dinner-plate-stacks/reverseInOrderIterator.ts" ;
2
2
import { InOrderIterator } from "./InOrderIterator.ts" ;
3
3
import { MultiRedBlackTree } from "./MultiRedBlackTree.ts" ;
4
-
4
+ import { Deque } from "https://esm.sh/@datastructures-js/deque@1.0.4/" ;
5
5
class MKAverage {
6
6
total = 0 ;
7
7
m : number ;
8
8
k : number ;
9
- queue = new Array < number > ( ) ;
9
+ queue = new Deque < number > ( ) ;
10
10
count = 0 ;
11
11
12
12
tree = new MultiRedBlackTree < number > ( ( a , b ) => a - b ) ;
@@ -16,7 +16,7 @@ class MKAverage {
16
16
}
17
17
18
18
addElement ( num : number ) {
19
- this . queue . push ( num ) ;
19
+ this . queue . pushBack ( num ) ;
20
20
21
21
this . tree . insert ( num ) ;
22
22
this . total += num ;
@@ -33,9 +33,9 @@ class MKAverage {
33
33
// }
34
34
// console.log(JSON.stringify(temp));
35
35
// }
36
- if ( this . queue . length === this . m + 1 ) {
37
- const willBeDelete : number = this . queue [ 0 ] ;
38
- this . queue . shift ( ) ;
36
+ if ( this . queue . size ( ) === this . m + 1 ) {
37
+ const willBeDelete : number = this . queue . front ( ) ;
38
+ this . queue . popFront ( ) ;
39
39
// console.log("deleteElement", willBeDelete);
40
40
this . total -= willBeDelete ;
41
41
this . tree . remove ( willBeDelete ) ;
You can’t perform that action at this time.
0 commit comments