0

How to remove all occurences from doubly linked list in java? Here is my code: Contents means the data in my node - it is String

void remove(String key){ DNode curr=head while (curr!=null){ if(curr.contents.compareTo(key)==0){ if (curr.prev==null){ curr=curr.next curr.prev=null numNodes--//this the number of nodes of my list} else if (curr.next==null){ curr=curr.prev curr.next=null numNodes--} else{ curr.prev.next=curr.next curr.next.prev=curr.prev numNodes--} curr=curr.next} } here is my code, the only problem here is i cannot remove a node at front, and can't find where is my problem. If you can help, please help me! Thank you

21st Apr 2018, 12:21 PM
Abdurakhmonjon Makhkamjonov
Abdurakhmonjon Makhkamjonov - avatar
1 Respuesta
+ 3
Put in the Code Playground. Also badly formatted code is far harder to read :-)
21st Apr 2018, 1:10 PM
Emma