Skip to content

Instantly share code, notes, and snippets.

@Preetiraj3697
Forked from rahul4coding/reversePrint.js
Last active October 21, 2022 05:46
Show Gist options
  • Save Preetiraj3697/00adb3e3642c5b38c72667cda24fc94c to your computer and use it in GitHub Desktop.
Save Preetiraj3697/00adb3e3642c5b38c72667cda24fc94c to your computer and use it in GitHub Desktop.
Reverse Print a given linkedList | JS
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);
}
}
@Preetiraj3697
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment