1516171819202122232425
import adt.LinkedList; public class Q015_Pairwise_Swap_Elements_Of_A_Given_Linked_List { public static void main(String[] args) { LinkedList list = new LinkedList(5); pairSwap(list); //pairSwapR(list.head); list.print(); }
16171819202122232425
public class Q012C_Remove_Duplicates_From_Unsorted_Linked_List { public static void main(String[] args) { int[] arr = {12, 11, 12, 21, 41, 43, 21}; LinkedList list = new LinkedList(arr); ListNode head = removeDups(list); head.print(); }
131415161718192021
import adt.LinkedList; public class Q032_Sort_a_linked_list_of_0s_1s_and_2s { public static void main(String[] args) { LinkedList list = new LinkedList(new int[]{0, 1, 0, 2, 1, 1, 2, 1, 2}); ListNode res = sortList(list.head); res.print(); }
1617181920212223242526
import adt.LinkedList; public class Q021_Identical_Linked_Lists { public static void main(String[] args) { LinkedList a = new LinkedList(new int[]{1, 2, 3}); LinkedList b = new LinkedList(new int[]{1, 2, 3}); boolean res = isIdentical(a.head, b.head); System.out.println(res); }
4142434445464748495051
return p; } public static void main(String[] args) { // Initialize a linked list LinkedList list = new LinkedList(10); ListNode node = getNth(list.head, 5); if (node != null) { System.out.println(node.val);
public class Q012B_Remove_Duplicates_From_Sorted_Linked_List { public static void main(String[] args) { int[] arr = {11, 11, 11, 21, 43, 43, 60}; LinkedList list = new LinkedList(arr); ListNode head = removeDups(list); head.print(); }
151617181920212223
import adt.LinkedList; public class Q018_Delete_Alternate_Nodes_of_Linked_List { public static void main(String[] args) { LinkedList list = new LinkedList(5); deleteAlternate(list); list.print(); }
2627282930313233
import adt.LinkedList; public class Q023_Delete_Nodes_Which_Have_A_Greater_Value_On_Right_Side { public static void main(String[] args) { LinkedList list = new LinkedList(new int[]{12, 15, 10, 11, 5, 6, 2, 3}); deleteGreaterNodes(list.head); }
222324252627282930
import adt.LinkedList; public class Q029_Rotate_a_Linked_List { public static void main(String[] args) { LinkedList list = new LinkedList(new int[]{10, 20, 30, 40, 50, 60}); leftRotate(list, 4); list.print(); }
64656667686970717273
public class Q026B_Sorted_Linked_List_to_Balanced_BST { static ListNode head; public static void main(String[] args) { LinkedList list = new LinkedList(new int[]{1, 2, 3, 4, 5, 6, 7}); head = list.head; TreeNode root = sortedListToBST(7); root.print(); }