Removing a range of values from a linked list -


i trying remove node linked list if value falls within range (greater or equal low , less or equal high). code removes first value found within range.

public void removedata(e low, e high) {     node previousnode = root;     node deletenode = previousnode.getnext();     while (deletenode != null) {         if (deletenode.getvalue().compareto(low) >= 0 && deletenode.getvalue().compareto(high) <= 0) {             previousnode.setnext(deletenode.getnext());         }         previousnode = previousnode.getnext();         deletenode = deletenode.getnext();     } } 

in code need is:

public void removedata(e low, e high) { node previousnode = root; node deletenode = previousnode.getnext(); while (deletenode != null) {     if (deletenode.getvalue().compareto(low) >= 0 && deletenode.getvalue().compareto(high) <= 0) {         previousnode.setnext(deletenode.getnext());     }else{         previousnode = previousnode.getnext();     }     deletenode = deletenode.getnext(); } 

}

because if 1 node deleted previous node doesn't need incremented deletenode has to. , check deletenode.

hope may you. thanks!!


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -