Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A sample of test execution artifacts: source code of program(s) used to perform testing, and screen captures, or etc. DLLNode.JAVA package ddladt; public class DLLNode

A sample of test execution artifacts: source code of program(s) used to perform testing, and screen captures, or etc.

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

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions