Skip to content

Commit cbd626f

Browse files
committed
Update MyLinkedList.ts
1 parent 3a4343b commit cbd626f

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lfu-cache/MyLinkedList.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,18 @@ export class MyLinkedList<T = number> {
77
this.#freq_list_head.next = this.#freq_list_tail;
88
this.#freq_list_tail.prev = this.#freq_list_head;
99
}
10-
10+
isEmpty() {
11+
return this.#freq_list_head.next === this.#freq_list_tail;
12+
}
13+
clear() {
14+
this.#freq_list_head.next = this.#freq_list_tail;
15+
this.#freq_list_tail.prev = this.#freq_list_head;
16+
}
17+
last_node() {
18+
return this.#freq_list_tail.prev === this.#freq_list_head
19+
? null
20+
: this.#freq_list_tail.prev;
21+
}
1122
first_node() {
1223
return this.#freq_list_head.next === this.#freq_list_tail
1324
? null
@@ -29,7 +40,7 @@ export class MyLinkedList<T = number> {
2940
}
3041
insert_After(
3142
prev_node: DoublyLinkedList<T>,
32-
new_node: DoublyLinkedList<T>,
43+
new_node: DoublyLinkedList<T>
3344
): void {
3445
const next = prev_node.next;
3546
const prev = prev_node;

0 commit comments

Comments
 (0)