Hello all, I am writing a program that requires me to add and view items from both the left and right (front and back) sides of a linked list. I have the left side figured out, but the right side is giving me trouble. I'm not really sure what to set my rightEnd equal to in the constructor.
Thanks for the help.
Here is my code:
public abstract class LinkedDeque implements DequeInterface {
private DNode leftEnd;
private DNode rightEnd;
private int size;
LinkedDeque()
{
leftEnd = new DNode(null);
rightEnd = new DNode(leftEnd);
size = 0;
}
// add to left end
public void addLeft(Disk obj)
{
leftEnd = new DNode(obj);
size++;
}
public void addRight(Disk obj)
{
}
public int getSize()
{
return size;
}
public DNode peekLeft()
{
if(size ==0)
{
throw new IllegalArgumentException("List is empty!");
}
return leftEnd;
}
public DNode peekRight()
{
if(size ==0)
{
throw new IllegalArgumentException("List is empty!");
}
return rightEnd;
}
}
Thanks for the help.
Here is my code:
public abstract class LinkedDeque implements DequeInterface {
private DNode leftEnd;
private DNode rightEnd;
private int size;
LinkedDeque()
{
leftEnd = new DNode(null);
rightEnd = new DNode(leftEnd);
size = 0;
}
// add to left end
public void addLeft(Disk obj)
{
leftEnd = new DNode(obj);
size++;
}
public void addRight(Disk obj)
{
}
public int getSize()
{
return size;
}
public DNode peekLeft()
{
if(size ==0)
{
throw new IllegalArgumentException("List is empty!");
}
return leftEnd;
}
public DNode peekRight()
{
if(size ==0)
{
throw new IllegalArgumentException("List is empty!");
}
return rightEnd;
}
}