theldro
asked on
Doubly linked list
Im trying to figure out how to set up a circular doubly linked list with a dummy head. I posted some code of my attempt to do this. The code is wrong and doesnt work. What do I need to add or remove to make it work right? I just want it to function as a circular doubly linked list with dummy head.
Thanks.
Thanks.
public class DLL
{
private Node head;
private int size;
public DLL()
{
head = null;
size = 0;
}
public int getSize()
{
return size;
}
public void setSize()
{
this.size = size;
}
}
//Do I need to add more to this class to make it work right?
public class Node
{
Node prev, next;
Object item;
private Node head;
public Node(Object data, DLL next, DLL prev)
{
this.head = new Node(null, null, null);
this.head = this.head;
this.prev = this.head;
int size = 0;
}
public Object getItem()
{
return this.item;
}
public void setItem(Object newItem)
{
this.item = newItem;
}
public Node getNext()
{
return this.next;
}
public void setNext(Node nextNode)
{
this.next = nextNode;
}
}
//Do I need to add or switch things in this class with DLL?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot. Now that I know what a circular doubly linked list with dummy head node looks like I can try to figure out how to do different things with it. I've only worked with singly linked lists so I only know how they work.
You need to add methods to the DLL class to add nodes, delete nodes and to display the linked list