简体   繁体   中英

Removing a node from a double linked list?

Here's the method up to now

public DNode removeDnode(DNode v, DNode e, DNode f)
{
    e = v.nextNode();
    f = v.prevNode();
    f.setNext() = e;
    e.setPrev() = f;
    v.setPrev(null);
    v.setNext(null);
    size = size - 1;
    return v;
}

Here's my node class

public class DNode
{

public String element;
public DNode next;
public DNode previous;

public DNode(String e, DNode n)
{
    element = e;
    next = n;
}    

public void setElement(String newElem) 
{ 
    element = newElem; 
}
public void setNext(DNode newNext) 
{ 
    next = newNext; 
}
public void setPrev(DNode newPrev)
{
    previous = newPrev;
}
public String getElement() 
{ 
    return element; 
}
public DNode nextNode() 
{
  return next;
}
public DNode prevNode() 
{
  return previous;
}

}

I'm getting the error 'method setNext in class DNode cannot be applied to given types but I don't know why. Any help?

(Don't read this this is to use characters so it will let me post)

EDIT: new method below

public DNode removeDnode(DNode current)
{
    DNode next = current.nextNode();
    DNode previous = current.prevNode();
    previous.setNext(next);
    next.setPrev(previous);
    current.setPrev(null);
    current.setNext(null);
    size = size - 1;
    return current;
}

but how do I deal with the end and beginning of the list

You need to do:

f.setNext(e);
e.setPrev(f);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM