File tree Expand file tree Collapse file tree 4 files changed +67
-2
lines changed
Expand file tree Collapse file tree 4 files changed +67
-2
lines changed Original file line number Diff line number Diff line change 1+ export class Node {
2+ constructor ( key , next = null ) {
3+ this . _key = key ;
4+ this . _next = next ;
5+ }
6+
7+ get key ( ) {
8+ return this . _key
9+ }
10+ get next ( ) {
11+ return this . _next ;
12+ }
13+ }
14+
15+
16+ const _size = Symbol ( 'size' ) ;
17+ const _head = Symbol ( 'head' ) ;
18+
19+ export class LinkedList {
20+ constructor ( ) {
21+ this [ _size ] = 0 ;
22+ this [ _head ] = null ;
23+ }
24+
25+ get head ( ) {
26+ return this [ _head ] ;
27+ }
28+
29+ size ( ) {
30+ return this [ _size ] ;
31+ }
32+
33+ isEmpty ( ) {
34+ return this . size ( ) === 0 ;
35+ }
36+
37+ search ( item ) { }
38+ insertLast ( item ) { }
39+ insertFirst ( item ) { }
40+ insertBefore ( item , before ) { }
41+ insertAfter ( item , after ) { }
42+ remove ( item ) { }
43+ }
Original file line number Diff line number Diff line change 1+ import { LinkedList } from './linked-list' ;
2+
3+ describe ( 'Linked List' , ( ) => {
4+ let list ;
5+ beforeEach ( ( ) => {
6+ list = new LinkedList
7+ } ) ;
8+
9+ it ( 'should create a linked list object' , ( ) => {
10+ expect ( list ) . toBeDefined ( ) ;
11+ expect ( list . size ( ) ) . toBe ( 0 ) ;
12+ expect ( list . head ) . toBe ( null ) ;
13+ expect ( list . isEmpty ( ) ) . toBeTruthy ( ) ;
14+ } ) ;
15+ } ) ;
Original file line number Diff line number Diff line change 11require ( './binary-search-tree/binary-search-tree.spec' ) ;
22require ( './graph/graph.spec' ) ;
3- require ( './queue/queue.spec' ) ;
43require ( './graph/adj-list.spec' ) ;
4+ require ( './queue/queue.spec' ) ;
5+ require ( './linked-list/linked-list.spec' ) ;
Original file line number Diff line number Diff line change @@ -34,8 +34,14 @@ declare namespace DataStructures {
3434 enqueue ( o ) : void ;
3535 dequeue ( ) : Error | void ;
3636 size ( ) : number ;
37- isEmpty ( ) : void ;
37+ isEmpty ( ) : boolean ;
3838 top ( ) : any ;
3939 clear ( ) : void ;
4040 }
41+
42+ class LinkedList {
43+ head ( ) : any ;
44+ size ( ) : number ;
45+ isEmpty ( ) : boolean ;
46+ }
4147}
You can’t perform that action at this time.
0 commit comments