Azienda coinvolta
Reverse a linked list.
Anonimo
Node ReverseLinkedList(Node head) { Node next = head.next; if (next == null) { return head; } Node revList = ReverseLinkedList(head.next); next.next = head; head.next = null; return revList; }
A recursive approach if anyone is interested. Only works for singly linked/non circular atm. called like: reverse(head, null); public static ListNode reverse(ListNode curr, ListNode prev) { if (curr == null) { return prev; } else { ListNode temp = curr.next; curr.next = prev; prev = curr; return reverse(temp, prev); } }
public static Node reverse(Node n) { if(n != null) { Node reversed.data = n.data; while(n.next != null) { Node insert; insert.data = n.next; insert.next = reversed; reversed = insert; n = n.next; } return reversed; } return null; }
Non lasciarti sfuggire opportunità e informazioni privilegiate seguendo le aziende dove vorresti lavorare.
Ricevi suggerimenti e aggiornamenti personalizzati avviando le tue ricerche.