reverse linked list in java to get both head and tail
/*
public class ListNode {
public int val;
public ListNode next;
public ListNode(int x) { val = x; next = null; }
}
*/
public static ListNode[] reverse_linked_list(ListNode head) {
ListNode prev = null;
ListNode current = head;
ListNode next;
ListNode tail = head;
while (current != null) {
next = current.next;
current.next = prev;
prev = current;
current = next;
}
head = prev;
ListNode[] result = {head, tail};
return result;
}
Also in Java:
- connect 2 package in android
- java d'intervalle de resultat
- java get command line input
- java indexof array
- how do I change the opacity of a JButton
- android studio keep device awake
- spigot chat color with symbol
- java hashmap size
- java using .indexof to fin a space
- main method java
- java file download
- java thread class sleep
- take a value from keyboard java
- update value of an arraylist java
- java simple jframe example
- how to fill a 2d array in java
- never gonna give you up
- java split for multiple characters
- java if a or b
- primitive data types in java
- map java
- java how to get current date
- java insert element at position
- java shuffle list