-
Notifications
You must be signed in to change notification settings - Fork 2
/
helper.ts
36 lines (31 loc) · 787 Bytes
/
helper.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// data type
export type DataType<T> = {
key: string|number
value: T
}
// singly linked list node class
export type NodeType = {
data: DataType<any>
next: null|NodeType
}|null
export class Node {
public data: DataType<any>
public next: NodeType|null = null
constructor(data: DataType<any>) {
this.data = data;
this.next = null;
}
}
// singly linked list interface
export interface LinkedListApi {
size: number;
prepend(data: DataType<any>): boolean;
append(data: DataType<any>): boolean;
add(data: DataType<any>, position: number): boolean;
getFromHead(): object|false;
getFromTail(): object|false;
print(): void;
remove(key: string|number): object|boolean;
update(key: string|number, newValue: any): object|boolean;
search(key: string|number): object|null
}