Skip to content

Instantly share code, notes, and snippets.

@bitcpf
Created June 25, 2014 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitcpf/943a20fc760f8ca4f6d3 to your computer and use it in GitHub Desktop.
Save bitcpf/943a20fc760f8ca4f6d3 to your computer and use it in GitHub Desktop.
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("");
}
}
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