Link to home
Start Free TrialLog in
Avatar of theldro
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.
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?

Open in new window

Avatar of a_b
a_b

private Node head; --> This in not required in the Node class

You need to add methods to the DLL class to add nodes, delete nodes and to display the linked list
ASKER CERTIFIED SOLUTION
Avatar of Keego7237
Keego7237

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of theldro

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.