Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 next,back;

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 next)

{

this.next = next;

}

public DLLNode returnNext()

// Returns next link of this DLLNode.

{

return next;

}

public void setBack(DLLNode back)

{

this.back = back;

}

public DLLNode getBack()

{

return back;

}

}

DLLAdt.JAVA

package ddladt;

public class DLLAdt

{

protected int elemNum;

protected DLLNode current;

protected DLLNode backCurrent;

protected boolean status;

protected DLLNode pos;

protected DLLNode backe;

protected DLLNode dlList;

protected DLLNode end;

//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 newNode = new DLLNode(element);

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 currNode = dlList;

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 dlList= new 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

What is the significance of entrepreneurship to the U.S. economy?

Answered: 1 week ago

Question

l List and explain four job analysis methods.

Answered: 1 week ago

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago