class Node{
constructor(value){
this.value=value
this.next = null
}
}
class Linklist{
constructor(value){
this.head = new Node(value)
this.tail = this.head
this.length=0
}
append(value){
const newNode = new Node(value)
this.tail.next = newNode
this.tail = newNode
return this
}
reverse(){
let current = this.head
let second = current.next
this.tail = this.head
while(second){
const temp = second.next
second.next = current
current = second
second = temp
}
this.head.next = null
this.head = current
}
}
const myLinklist = new Linklist(-10)
myLinklist.append(10)
myLinklist.append(20)
myLinklist.reverse()
console.log(myLinklist)