-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_LList.ts
109 lines (82 loc) · 1.61 KB
/
test_LList.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import {List,DLList,CLList,Node} from "./LinkedList";
let prt = console.log;
interface N {
no?:number;
str?:string;
}
let a:N = {no:1, str:"a"};
let b:N = {no:2, str:"b"};
let c:N = {no:3, str:"c"};
let d:N = {no:4, str:"d"};
prt("------ SLList Test -----");
let sl = new List<N>();
sl.insertTail(a);
sl.insert(c,a);
sl.display();
prt(sl.find(b));
prt(sl.find(a));
sl.insertTail(b);
sl.display();
sl.insert(d);
sl.display();
prt(" advance");
let node = sl.find(a);
prt(sl.advance(2,node));
prt(sl.advance(3));
prt(sl.count());
prt("---- remove ")
sl.remove(b);
sl.display();
sl.remove(a);
sl.display();
prt(sl.count());
prt("------ DLList Test -----");
let dl = new DLList<N>();
dl.insert(a)
dl.insert(b);
dl.insert(c,a);
dl.dispReverse(); // b->c->a
dl.display(); // a -> c -> b
prt("--- find check")
prt(dl.find(c));
prt(dl.findLastNode());
prt("-- insert tail");
dl.insertTail(d);
dl.display(); // a c b d
prt("--- back");
let nd = dl.find(d);
// prt(nd);
prt(dl.back(2,nd));
prt(dl.back(4));
prt("--- remove");
dl.remove(c);
dl.dispReverse();
dl.insert(c,b);
dl.display();
prt('--- remove the first and last node');
dl.remove(d);
dl.display();
dl.remove(a);
dl.display();
prt("------ CLList Test -----");
let cl = new CLList<N>();
cl.insert(a)
cl.insert(b);
cl.insert(c,a);
cl.display(); // a -> c -> b
prt("--- find check")
prt(cl.find(c));
prt(cl.findLastNode());
prt("-- insert tail");
cl.insertTail(d);
cl.display(); // a c b d
prt("--- remove");
cl.remove(c);
cl.display();
cl.insert(c,b);
cl.display();
prt('--- remove the first and last node');
cl.remove(d);
cl.display();
cl.remove(a);
cl.display();