Sort by

recency

|

915 Discussions

|

  • + 0 comments

    function reverse(llist) { var node = null; while(llist != null) { var temp = node; node = new SinglyLinkedListNode(llist.data,temp) node.next = temp llist = llist.next } return node

    }

  • + 0 comments

    javascript solution:

    ` function reverse(llist) { let prev, next = null;

    while (llist !== null) { [next, llist.next] = [llist.next, prev]; [prev, llist] = [llist, next]; } return prev; 

    } `

  • + 0 comments

    Great approach! Reversing a singly linked list by inserting nodes at the beginning of a new list is efficient and clean. This function is especially useful in coding interviews and beginner data structure practice.

    Also, if anyone is looking for a peaceful break from coding or wants to learn to read the Quran online, I invite you to visit my website: πŸ‘‰ Zeenat ul Quran – Online Quran Learning Platform

    It’s a great resource for all ages to learn Quran, namaz, and Islamic basics from home. 😊

  • + 0 comments

    My python solution :

    def reverse(llist): llist_2 = SinglyLinkedList() current = llist while current : node = SinglyLinkedListNode(current.data) node.next = llist_2.head llist_2.head = node current = current.next return llist_2.head 
  • + 0 comments

    My Java solution:

    public static SinglyLinkedListNode reverse(SinglyLinkedListNode llist) { SinglyLinkedListNode reverseList = null; SinglyLinkedListNode current = llist; while (current != null) { SinglyLinkedListNode temp = new SinglyLinkedListNode(current.data); temp.next = reverseList; reverseList = temp; current = current.next; } return reverseList; }