Data Structure : remove live code & console.log

This commit is contained in:
Eric Lavault
2021-10-10 16:11:06 +02:00
parent 30779682b9
commit a3d44ad3e1
8 changed files with 32 additions and 153 deletions

View File

@ -73,25 +73,16 @@ class SinglyCircularLinkedList {
this.size--
}
printData () {
printData (output = value => console.log(value)) {
let count = 0
let current = this.head
while (current !== null && count !== this.size) {
console.log(current.data + '\n')
while (current !== null && count < this.size) {
output(current.data)
current = current.next
count++
}
}
}
const ll = new SinglyCircularLinkedList()
ll.insert(10)
ll.insert(20)
ll.insert(30)
ll.insert(40)
ll.insert(50)
ll.insertAt(5, 60)
ll.remove(5)
ll.printData()
export { SinglyCircularLinkedList }

View File

@ -180,12 +180,12 @@ const LinkedList = (function () {
}
// Function to view the LinkedList
LinkedList.prototype.view = function () {
LinkedList.prototype.view = function (output = value => console.log(value)) {
let currentNode = this.head
let count = 0
while (count < this.length) {
count++
console.log(currentNode.element)
output(currentNode.element)
currentNode = currentNode.next
}
}
@ -194,16 +194,4 @@ const LinkedList = (function () {
return LinkedList
}())
// Implementation of LinkedList
const linklist = new LinkedList()
linklist.add(2)
linklist.add(5)
linklist.add(8)
linklist.add(12)
linklist.add(17)
console.log(linklist.size())
console.log(linklist.removeAt(4))
linklist.addAt(4, 15)
console.log(linklist.indexOf(8))
console.log(linklist.size())
linklist.view()
export { LinkedList }