reverse() {
let current = this.head;
let next = null;
let previous = null;
while(current !== null) {
next = current.next;
current.next = previous;
previous = current;
current = next;
}
this.head = previous;
}
visualization video:
https://www.youtube.com/watch?v=D7y_hoT_YZI&ab_channel=GeeksforGeeks
Top comments (0)