Skip to content

Commit 5ebda86

Browse files
committed
added CircularLinkedList class in ES6 syntax
1 parent d69668f commit 5ebda86

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

chapter05/05-CircularLinkedList2.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ let CircularLinkedList2 = (function () {
5656
previous,
5757
index = 0;
5858

59-
if (position === 0) { //add on first position
59+
if (position === 0) { //add on first position
6060

6161
node.next = current;
6262

6363
//update last element
64-
while (current.next !== head) { //last element will be head instead of NULL
64+
while (current.next !== this.getHead()) { //last element will be head instead of NULL
6565
current = current.next;
6666
}
6767

@@ -101,7 +101,7 @@ let CircularLinkedList2 = (function () {
101101
//removing first item
102102
if (position === 0) {
103103

104-
while (current.next !== head) { //needs to update last element first
104+
while (current.next !== this.getHead()) { //needs to update last element first
105105
current = current.next;
106106
}
107107

chapter05/06-UsingCircularLinkedList.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
let circularLinkedList = new CircularLinkedList2();
22

3-
/*circularLinkedList.append(15);
3+
circularLinkedList.append(15);
44
circularLinkedList.print();
55

66
circularLinkedList.append(16);
@@ -25,4 +25,4 @@ circularLinkedList.removeAt(2);
2525
circularLinkedList.print();
2626

2727
console.log(circularLinkedList.indexOf(14.5));
28-
console.log(circularLinkedList.indexOf(16));*/
28+
console.log(circularLinkedList.indexOf(16));

0 commit comments

Comments
 (0)