anish000kumar
11/9/2018 - 5:43 PM

reverse a linked list

reverse a linked list


function reverseLinkedList(head){
    
    let prev = null;
    let next = null;
    
    while(head){
        next = head.next;
        head.next = prev;
        prev = head;
        head = next;
    }
    
    return prev;
    
}