## Tuesday, December 23, 2014

### An algorithm to delete a node in the middle of a singly linked list, given only access to that node.

Q. Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node.

EXAMPLE

Input: the node c from the linked list a->b->c->d->e
Result: nothing is returned, but the new linked list looks like a->b->d->e

Source:

```public class Code{
if(node.next == null)return; //End node provided
node = node.next;

while(node.next!=null){
prev.value = node.value;
prev = node;
node = node.next;
}
prev.value = node.value;
prev.next = null;
}

for(int i=0;node.next!=null && i<=index-1;++i){
node = node.next;
}
return node;
}

public static <T> LinkedList<T> buildList(T[] a){
return ll;
}

public static void main(String[] args){
Character array[] = new Character[]{'A','E','I','O','U'};
deleteMiddleNode(node);
System.out.println(ll);
}
}```

```public class LinkedList <T>{

class Node{
Node next;
T value;

Node(T value){this.value = value;}
}

while(t.next!=null){t = t.next;}
t.next = new Node(value);
}

public boolean isEmpty(){
}

@Override
public String toString(){
StringBuilder bf = new StringBuilder();
while(t!=null){
bf.append(t.value);
t = t.next;
}
return bf.toString();
}
}```

Output:

AEOU