@@ -0,0 +1,1842 @@
+package com.sunny.grokkingalgorithms.ctc.c2;%0A%0Aimport com.sunny.grokkingalgorithms.ctc.c2.util.LinkedListUtil;%0Aimport com.sunny.grokkingalgorithms.ctc.c2.util.Node;%0A%0A/**%0A * Created by sundas on 3/14/2018.%0A */%0Apublic class DeleteMiddleOfLinkedListGivenReference %7B%0A%0A  /*%0A  Given reference to a node , delete it from the linked list.If it is last element you%0A  will not be delete it.%0A%0A  a-%3Eb-%3Ec-%3Ed%0A  delete c%0A  after deletion%0A  a-%3Eb-%3Ed%0A   */%0A%0A  /**%0A   *%0A   * @param middle%0A   */%0A  public static void deleteNodeFromMiddle(Node middle)%7B%0A    if(middle != null%0A        && middle.next != null)%7B%0A      /*%0A      Copy next node's value into middle which is essentailly line overwriting existing middle's value and then%0A      delete next%0A       */%0A      middle.data = middle.next.data;%0A      middle.next = middle.next.next;%0A    %7D%0A  %7D%0A%0A  /**%0A   *%0A   * @param root%0A   * @return%0A   */%0A  public static Node findMiddleOfLinkedList(Node root)%7B%0A    /*%0A    Once again we use the fast runner apporach. The fast runner covers twice as much noes as slow%0A     runner so when fast runner will be at the end, slow runner will be in the middle%0A     */%0A    Node slowRunner = root;%0A    Node fastRunner = root;%0A    while(fastRunner != null && slowRunner != null)%7B%0A      slowRunner = slowRunner.next;%0A      fastRunner = fastRunner.next;%0A      if(fastRunner != null)%7B%0A        fastRunner = fastRunner.next;%0A      %7D%0A    %7D%0A    //Now slow runner is at the middle%0A    return slowRunner;%0A  %7D%0A%0A  /**%0A   *%0A   * @param args%0A   */%0A  public static void main(String%5B%5D args) %7B%0A    int%5B%5D input = new int%5B%5D%7B1,2,3,4,5,6,7,8%7D;%0A    Node root = LinkedListUtil.createLinkedList(input);%0A    LinkedListUtil.printLinkedList(root);%0A    Node middle = findMiddleOfLinkedList(root);%0A    System.out.println(middle.data);%0A    deleteNodeFromMiddle(middle);%0A    LinkedListUtil.printLinkedList(root);%0A  %7D%0A%7D%0A

Delete node from middle of linked list.