1
+ const DoublyLinkedList = require ( '../doublyLinkedList.js' ) ;
2
+
3
+ class CircularDoublyLinkedList extends DoublyLinkedList
4
+ {
5
+
6
+ printCircularLinkedList ( )
7
+ {
8
+ let current = this . head ;
9
+
10
+ console . log ( 'Circular Singly Linked List:' ) ;
11
+
12
+ for ( let i = 0 ; i < this . size ; i ++ )
13
+ {
14
+ console . log ( current ) ;
15
+ current = current . next ;
16
+
17
+ if ( current . next === null ) current . next = this . head ;
18
+ }
19
+ }
20
+ }
21
+
22
+ // The lines below are not part of the data structure
23
+
24
+ /*
25
+ const circularDoublyLinkedList = new CircularDoublyLinkedList();
26
+ circularDoublyLinkedList.prepend(100);
27
+ circularDoublyLinkedList.append(500);
28
+
29
+ circularDoublyLinkedList.prepend(300);
30
+
31
+ circularDoublyLinkedList.append(1000);
32
+
33
+ circularDoublyLinkedList.insertAt(400,2);
34
+
35
+ circularDoublyLinkedList.insertAt(200,0);
36
+
37
+ circularDoublyLinkedList.length();
38
+ circularDoublyLinkedList.printData();
39
+
40
+ circularDoublyLinkedList.printLinkedList();
41
+
42
+ circularDoublyLinkedList.printCircularLinkedList();
43
+
44
+ circularDoublyLinkedList.getData(300);
45
+ circularDoublyLinkedList.getData(3000);
46
+ circularDoublyLinkedList.getIndex(4);
47
+
48
+ circularDoublyLinkedList.removeIndex(2);
49
+
50
+ circularDoublyLinkedList.length();
51
+
52
+ circularDoublyLinkedList.printData();
53
+
54
+ circularDoublyLinkedList.printCircularLinkedList();
55
+
56
+ circularDoublyLinkedList.clear();
57
+
58
+ circularDoublyLinkedList.length();
59
+
60
+ circularDoublyLinkedList.printData();
61
+ */
0 commit comments