Created
June 25, 2014 16:50
-
-
Save bitcpf/943a20fc760f8ca4f6d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Delmiddle { | |
public static boolean Delmid(Node<Integer> mid){ | |
if (mid.next == null || mid == null){ | |
return false; | |
} | |
else{ | |
mid.item = mid.next.item; | |
mid.next = mid.next.next; | |
return true; | |
} | |
} | |
public static void main(String[] args){ | |
Node<Integer> a = new Node<Integer>(1); | |
Node<Integer> b = new Node<Integer>(2); | |
Node<Integer> c = new Node<Integer>(3); | |
Node<Integer> d = new Node<Integer>(4); | |
Node<Integer> e = new Node<Integer>(5); | |
a.next = b; | |
b.next = c; | |
c.next = d; | |
d.next = e; | |
printlist(a); | |
if (Delmid(c)){ | |
printlist(a); | |
} | |
} | |
public static void printlist(Node<Integer> head){ | |
Node<Integer> temp = head; | |
while(temp.next != null){ | |
System.out.print(temp.item + " "); | |
temp = temp.next; | |
} | |
System.out.print(temp.item + " "); | |
System.out.println(""); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Node<Item> { | |
public Item item = null; | |
public Node<Item> next = null; | |
public Node (Item item) { | |
this.item = item; | |
this.next = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment