-
-
Save Preetiraj3697/00adb3e3642c5b38c72667cda24fc94c to your computer and use it in GitHub Desktop.
Reverse Print a given linkedList | JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const LinkedListNode = class { | |
constructor(nodeData) { | |
this.data = nodeData; | |
this.next = null; | |
} | |
} | |
// Complete the function below | |
function reversePrint(head) { | |
if(head!==null){ | |
reversePrint(head.next); | |
return console.log(head.data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reverse the Linked List -60:45:10
Description
Given the pointer to the head node of a linked list, change thepointers of the nodes so that their order is reversed. The head pointer given may be null meaning that the initial list is empty.
Complete thereversefunction in the editor below.
reversehas the following parameter:
LinkedListNode pointer head:a reference to the head of a list
Sample Input 1
1
5
1
2
3
4
5
Sample Output 1
5 4 3 2 1