Question
Overall description of the project, that includes a brief description of the List ADT. please put in paragraph form what to do for the project
Overall description of the project, that includes a brief description of the List ADT. please put in paragraph form
what to do for the project
Design, implement and test a List ADT implementation based on a doubly linked list that uses the authors' DLLNode object (found in the support folder). In addition to the authors' standard list operations , your class must support backward iteration through the list via resetBack and getPrevious methods. The authors suggest including an instance variable that always references the last element on the list. Consider the remove operation for a doubly linked list and design and create the code for remove. Remember to handle all of the special cases.
DLLNode.JAVA
package ddladt;
public class DLLNode
{
private DLLNode
private T info;
public DLLNode(T info)
{
this.info = info;
next = null;
}
public void setInfo(T info)
{
this.info = info;
}
public T getInfo()
{
return info;
}
public void setNext(DLLNode
{
this.next = next;
}
public DLLNode
// Returns next link of this DLLNode.
{
return next;
}
public void setBack(DLLNode
{
this.back = back;
}
public DLLNode
{
return back;
}
}
DLLAdt.JAVA
package ddladt;
public class DLLAdt
{
protected int elemNum;
protected DLLNode
protected DLLNode
protected boolean status;
protected DLLNode
protected DLLNode
protected DLLNode
protected DLLNode
//class constructor
public DLLAdt()
{
elemNum = 0;
dlList = null;
end = null;
current = null;
backCurrent = null;
}
//to insert to dd list
public void add(T element)
{
DLLNode
if(dlList==null)
{
dlList = newNode;
end = dlList;
}
else
{
dlList.setBack(newNode);
newNode.setNext(dlList);
dlList = newNode;
}
elemNum++;
}
protected void find(T target)
{
pos = dlList;
status = false;
while (pos != null)
{
if (pos.getInfo().equals(target))
{
status = true;
return;
}
else
{
backe = pos;
pos = pos.returnNext();
}
}
}
//to get the size
public int size()
{
return elemNum;
}
//to check the presence of an entry
public boolean contains (T element)
{
find(element);
return status;
}
//to delete entries from the list
public boolean delete (T element)
{
find(element);
if (status)
{
if (dlList == pos)
dlList = dlList.returnNext();
else
backe.setNext(pos.returnNext());
elemNum--;
}
return status;
}
public T get(T element)
{
find(element);
if (status)
return pos.getInfo();
else
return null;
}
public String toString()
{
DLLNode
String listString = "List: ";
while (currNode != null)
{
listString = listString + " " + currNode.getInfo() + " ";
currNode = currNode.returnNext();
}
return listString;
}
//reset teh list
public void reset()
{
current = dlList;
}
public void backReset()
{
backCurrent = end;
}
public T returnNext()
{
T next = current.getInfo();
if (current.returnNext() == null)
current = dlList;
else
current = current.returnNext();
return next;
}
//get previous
public T getPrevious()
{
T pre = backCurrent.getInfo();
if (backCurrent.getBack() == dlList)
backCurrent = end;
else
backCurrent = backCurrent.getBack();
return pre;
}
}
Test.JAVA
package ddladt;
//The driver program
public class Test
{
public static void main(String args[])
{
DLLAdt
for(int itr=100;itr>1;itr-=10)
dlList.add(itr);
System.out.println(dlList.toString());
dlList.reset();
dlList.backReset();
System.out.println(" Testing the returnNext() function");
System.out.print(" "+dlList.returnNext().intValue());
System.out.print(" "+dlList.returnNext().intValue());
System.out.print(" "+dlList.returnNext().intValue());
System.out.println(" Testing the getPrevious() function");
System.out.print(" "+dlList.getPrevious().intValue());
System.out.print(" "+dlList.getPrevious().intValue());
System.out.print(" "+dlList.getPrevious().intValue());
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started