Package adt

Examples of adt.LinkedList


public class Q008_Check_If_A_Singly_Linked_List_Is_Palindrome {
 
  public static void main(String[] args) {
    // initialize the list
    LinkedList list = new LinkedList();
    int[] arr = {1, 2, 3, 4, 3, 2, 1};
    list.append(arr);
    list.print();
   
    // check if it's palindrome
    boolean res = isPalindrome(list);
   
    System.out.println(res);
View Full Code Here


import adt.LinkedList;

public class Q014_Move_Last_Element_To_Front_Of_A_Given_Linked_List {
 
  public static void main(String[] args) {
    LinkedList list = new LinkedList(5);
    moveLastToFront(list);
    list.print();
  }
View Full Code Here

import adt.LinkedList;

public class Q035A_Swap_Kth_node_from_beginning_with_Kth_node_from_end_in_a_Singly_Linked_List {

  public static void main(String[] args) {
    LinkedList list = new LinkedList(8);
    ListNode head = swap(list.head, 3);
    head.print();
  }
View Full Code Here

import adt.LinkedList;

public class Q003_Print_The_Middle_Of_A_Given_Linked_List {

  public static void main(String[] args) {
    LinkedList list = new LinkedList(9);
    ListNode middle = getMiddleNode(list.head);
   
    if (middle != null) {
      System.out.println(middle.val);
    } else {
View Full Code Here

import adt.LinkedList;

public class Q017_Intersection_of_Two_Sorted_Linked_Lists {

  public static void main(String[] args) {
    LinkedList l1 = new LinkedList(new int[]{1, 2, 3, 4, 6});
    LinkedList l2 = new LinkedList(new int[]{2, 4, 6, 8});
    ListNode head = getIntersection(l1.head, l2.head);
    head.print();
  }
View Full Code Here

import adt.LinkedList;

public class Q009_Copy_Linked_List_With_Next_And_Arbit_Pointer {
 
  public static void main(String[] args) {
    LinkedList list = new LinkedList(10);
    copyLinkedList(list);
  }
View Full Code Here

import adt.LinkedList;

public class Q004_Nth_Node_From_The_End_Of_A_Linked_List {
 
  public static void main(String[] args) {
    LinkedList list = new LinkedList(10);
   
    ListNode node = lastNthNode(list.head, 3);
   
    if (node != null) {
      System.out.println(node.val);
View Full Code Here

import adt.ListNode;

public class Q060_Construct_Complete_Binary_Tree_from_its_Linked_List_Representation {

  public static void main(String[] args) {
    LinkedList list = new LinkedList(new int[]{10, 12, 15, 25, 30, 36});
    TreeNode root = constructTree(list.head);
    root.print();
  }
View Full Code Here

import adt.LinkedList;

public class Q007_Detect_Loop_In_A_Linked_List {

  public static void main(String[] args) {
    LinkedList list = new LinkedList();
   
    ListNode node1 = list.append(1);
    ListNode node2 = list.append(2);
    ListNode node3 = list.append(3);
    ListNode node4 = list.append(4);
    ListNode node5 = list.append(5);
   
    // make a loop
    node5.next = node2;
   
    boolean res = detectLoop(list);
View Full Code Here

import adt.tree.TreeNode;

public class Q026A_Sorted_Linked_List_to_Balanced_BST {

  public static void main(String[] args) {
    LinkedList list = new LinkedList(new int[]{1, 2, 3, 4, 5, 6, 7});
    TreeNode root = sortedListToBST(list.head);
    root.print();
  }
View Full Code Here

TOP

Related Classes of adt.LinkedList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.