SlideShare a Scribd company logo
PROBLEM STATEMENT:
In this assignment, you will complete DoubleEndedList.java that implements the ListInterface as
well as an interface called DoubleEndedInterface which represents the list's entries by using a
chain of nodes that has both a head reference and a tail reference. Be sure to read through the
code and understand the implementation.
WHAT IS PROVIDED:
- A driver class to test your code. You should not modify this file!
- A list interface (ListInterface.java)
- A double ended interface (DoubleEndedInterface.java)
- An incomplete DoubleEndedList class (DoubleEndedList.java)
WHAT YOU NEED TO DO:
4. Complete the DoubleEndedList class
4. Run the driver and make sure your output is exactly the same as mine (at the bottom of
Driver.java)
} // end else numberofEntries--; else throw new IndexOut0fBoundsException("Illegal position
given to remove operation."); return result; // Return removed entry }//endreturnreve public T
replace(int givenPosition, T newEntry) { T replace(int givenPosition, T newEntry) { if
((givenPosition >=1)&& (givenPosition <= numberOfEntries)) { // Assertion: The list is not
empty Node desiredNode = getNodeAt (givenPosition); ToriginalEntry = desiredNode.getData();
desiredNode.setData(newEntry); return originalEntry; f // end if else throw new
IndexOut0fBoundsException("Illegal position given to replace operation."); replace if ((
givenPosition >=1)&& (givenPosition <= number0fEntries)) { // Assertion: The list is not
empty Node desiredNode = getNodeAt ( givenPosition); T originalEntry = desiredNode.
getData( ); desiredNode.setData(newEntry); return originalentry; } // end if throw new
Index0ut0fBoundsException("Illegal position given to replace operation."); } // end replace
public T getEntry(int givenPosition) { if ((givenPosition >=1) && (givenPosition < =
number0fEntries ) ) { // Assertion: The list is not empty return getNodeAt (givenPosition).
getData(); else // end if throw new IndexOut0fBoundsException("Illegal position given to
getEntry operation."); } // end getEntry public boolean contains ( T anEntry) { boolean found =
false; Node currentNode = firstNode; while (!found && (currentNode != null)) { if
(anEntry.equals (currentNode.getData())) else found = true; } // end while currentNode =
currentNode. getNextNode () ; return found; } // end contains public int getLength() { return
numberofEntries; } // end getLength public boolean isEmpty() { return number0fEntries ==0;
} // end isEmpty public T[] toArray() { // The cast is safe because the new array contains null
entries aSuppressWarnings ("unchecked") T[] result =(T[]) new 0bject [numberofEntries]; //
Unchecked cast int index =0; Node currentNode = firstNode; while ((index < numberOfEntries)
&& (currentNode != null)) & result [ index ]= currentNode. getData () ; currentNode =
currentNode.getNextNode ( ); index++; 3 // end while return result; 3 // end toArray // Returns a
reference to the node at a given position. // Precondition: List is not empty; 1<= givenPosition <
= numberofEntries. // Assertion: (firstNode != null) and (1<= givenPosition) and (givenPosition
<= // numberofEntries) Node currentNode = firstNode; if (givenPosition == numberofEntries)
currentNode = lastNode; else if (givenPosition >1 ) // Traverse the chain to locate the desired
node for (int counter =1; counter < givenPosition; counter++) currentNode = currentNode.
getNextNode () ; assert currentNode != null; return currentNode; } // end getNodeAt private
class Node { private T data; // Data portion private Node next; // Next to next node data =
dataPortion; } // end constructor data = dataPortion; } // end constructor private T getData() {
} // end return data; private void setData( T newData) { data = newData; } // end setData
private Node getNextNode() { return next; } // end getNextNode private void
setNextNode(Node nextNode) { next = nextNode; } // end setNextNode } // end Node
1** A class that implements the ADT double-ended list by using a chain of nodes. * The chain
has both a head reference and a tail reference. * Position numbers begin with 1 . * Q eauthor
Frank M. Carrano * dauthor Joseph Erickson */ aversion 5.0 public class DoubleEndedList
implements ListInterface , DoubleEndedInterface { private Node firstNode; // Head reference to
first node private Node lastNode; // Ta private int numberofEntries; public DoubleEndedList() {
} clear (); // ============= // ADDED METHODS: public void addFirst(T newEntry) f } //
end addFirst public void addLast (T newEntry) { } // end addLast public T removefirst() { } //
end removefirst public T removelast() { } // end removelast public T getFirst() { } // end
getFirst public T getLast () { } // end getLast public void moveToEnd() { } // end moveToEnd
// ====================== public final void clear() firstNode = null; lastNode = null;
numberOfEntries =0 } // end clear public void add ( T newEntry) { Node newNode = new Node
(newEntry); // Create new node if (isEmpty()) else firstNode = newNode; las tNode.
setNextNode (newNode); lastNode = newNode; numberOfEntries++; 3 // end add if ((
newPosition >=1)&& (newPosition <= numberofEntries +1)){ Node newNode = new Node
(newEntry); if (isEmpty()) firstNode = newNode lastNode = newNode; }// end if else if
(newPosition =1 ) { newNode. SetNextNodel first Node = newNode; 3 // end else if
(newPosition == numberOfEntries +1 ) { lastNode. setNextNode (newNode); last Node =
newNode; } // end else { Node nodeBefore = getNodeAt ( newPosition -1); Node nodeAfter =
nodeBefore.getNextNode () newNode. setNextNode (nodeAfter); 3 // end else } // end if else }
// end add throw new IndexOut0fBoundsException("Illegal position given to add operation.");
public T remove(int givenPosition) { T result = null; // Return value if ((givenPosition >=1)&&
(givenPosition <= number0fEntries)) { // Assertion: The list is not empty result = firstNode.
getData ();// Save entry to be removed firstNode = firstNode.getNextNode( ); if (numberofentries
=1 ) } // end if lastNode = null; // Solitary entry was removed else // Case 2: givenPosition > 1
Node nodeBefore = getNodeAt (givenPosition -1); Node nodeToRemove = nodeBefore.
getNextNode (); Node nodeAfter = nodeToRemove. getNextNode (); Node nodeAfter =
nodeToRemove.getNextNode (); nodeBefore.setNextNode(nodeAfter); // Disconnect the node to
be removed result = nodeToRemove.getData(); // Save entry to be removed if (givenPosition ==
numberofentries) lastNode = nodeBefore; // Last node was removed } // end else
numberofEntries--; else throw new Indexout0fBoundsException("Illegal position given to
remove operation."); return result; // Return removed entry remove } // end remove public T
replace(int givenPosition, T newEntry) { venPosition >=1)&& (givenPosition <=
numberofentries) ) { Node desiredNode = getNodeAt (givenPosition); ToriginalEntry =
desiredNode.getData( ); return originalData (newEntry); } // end if throw new
IndexOut0fBoundsException("Illegal position given to replace operation.");
An interface for a collection that has a first entry and a last entry. @author Frank M. Carrano
Qversion 5.0 / ablic interface DoubleEndedInterface {/ * Adds a new entry to the beginning of
this collection. * @param newEntry The object to be added as a new entry. 1 public void
addFirst(T newEntry); /** * Adds a new entry to the end of this collection. * Qparam newEntry
The object to be added as a new entry. / public void addLast( T newEntry); /** * Removes and
returns the first entry in this collection. * areturn A reference to the removed entry or null, if *
the list was empty. / public T removefirst(); /** * Removes and returns the last entry in this
collection. * Qreturn A reference to the removed entry or null, if * the list was empty. / public T
removelast(); /** * Retrieves the first entry in this collection. * areturn A reference to the first
entry or null, if * the list is empty. 1 public T getFirst(); /** * Retrieves the last entry in this
collection. * Qreturn A reference to the last entry or null, if * the list is empty. / public T
getLast(); /** Moves the first entry in this collection to the end of the list. */ public void
moveToEnd(); // end DoubleEndedInterface
ver that demonstrates the class DoubleEndedList. thest only the additional methods, since the
methods or Frank M. Carrano ion 5.0 lass Driver { lass Driver { public static void
main(String[] args) { System.out.println("Create an empty list."); System. out.print ln("Create
an empty list."); DoubleEndedList < String > myList = new DoubleEndedList <();
System.out.println("List should be empty; isEmpty() returns " + myList.isEmpty() + ".");
System.out.print ln("nTesting addFirst:"); myList.addFirst ("15"); myList. addFirst (" 25 ")
mylist.addFirst (" 45) System.out.println("List should contain 453525 15."); myList.clear();
mylist.clear(); myList. addLast ("15"); myList.addLast ("35") myList.addLast (" 45)
myList.addLast ("55"); myList. addLast ("65"); displaylist (myList); System.out.print
ln("nTesting removeFirst with previous list:"); System.out.println("removeFirst (): " + myList.
removeFirst ()); System. out.println("nList should containn45 5565 "); displayList (myList);
System. out.println("removefirst(): " + myList. removeFirst()); System.
out.println("removefirst(): " + myList. removefirst()); System. out.println("List should be empty;
isEmpty() returns" + myList.isEmpty() + "."); myList.clear(); myList. addLast ("15");
myList.addLast (" 25 ") myList. addLast ("45"); myList. addLast ("55"); System.out.println("List
should contain 1525354555 65."); displaylist (myList); System.out.println("removeLast (): " +
myList.removeLast()); System.out.println("removeLast (): " + myList.removeLast ()); System.
out.print ln ("removeLast (): " + myList. removeLast ()) System. out.print ln ("removeLast (): " +
mylist.removelast ()); System.out.println("nList should contain n15"); displaylist (myList); ( )
System.out.print ln("nTesting getFirst and getlast with the following list:"); myList.clear()
myList.addLast ("15"); myList.addLast (" 25 "); myList. addLast ("35"); myList. addLast (" 55)
myList.addLast ("65"); displayList (myList): System.out.println("Retrieving the first entry :
returns " + myList.getFirst()); System.out.print ln("nTesting moveToEnd with the following
list:"); displayList (myList); myList. moveToEnd () System. out.println("After moveToEnd, the
list is:"); displaylist (myList); myList. moveToEnd ( ) System.out.println("After moveToEnd, the
list is:"); displaylist (myList); myList. moveToEnd ( ) System.out.println("After moveToEnd, the
list is:"); displaylist (mylist); System. out.print ln ("nnDone."); public static void
displayList(ListInterface aList) { System.out.println("The list contains " + aList.getLength() +
"string(s), as follows:"); Object [] listArray = aList. toArray(); for (int index =0; index <
listarray. length; index++) { } // end for System.out.print ln(); for (int position =1; position <=
listarray. length; position++) { if (position < 10) else System.out.print(" " + position);
System.out.print (position); System.out.print(" "); }//endfor System.out.print ln(); H/ end Driver
e an empty list. should be empty; isEmpty() returns true. son list. ng addFirst: should contain
45352515 ist contains 4 string(s), as follows: 4 ng addlast with the following list: should contain
152535455565. ist contains 456
* Testing removefirst with previous list: * removefirst(): 15 * removeFirst(): 25 * removeFirst():
35 * List should contain * 455565 * The list contains 3 string(s), as follows: * 455565 * 123 *
removeFirst(): 45 * removeFirst(): 55 * removeFirst(): 65 * removefirst(): null * List should be
empty; isEmpty() returns true. * * Testing removelast with the following list: * List should
contain 152535455565 . * The list contains 6 string(s), as follows: * 152535455565 * 123456 *
removeLast (): 65 * removelast (): 55 * removelast (): 45 * removelast (): 35 * removeLast (): 25
* List should contain * 15 * The list contains 1 string(s), as follows: * 15 * 1 * removelast (): 15
* removelast (): null * List should be empty; isEmpty() returns true. * Testing getFirst and
getlast with the following list: * The list contains 6 string(s), as follows: * 152535455565 *
123456 * Retrieving the first entry : returns 15 * Retrieving the last entry : returns 65 * Testing
moveToEnd with the following list: * The list contains 6 string(s), as follows: * 152535455565 *
123456 * After moveToEnd, the list is: * The list contains 6 string(s), as follows: *
253545556515 * 123456 * After moveToEnd, the list is: * The list contains 6 string(s), as
follows: * 354555651525 * 123456 * After moveToEnd, the list is: * The list contains 6
string(s), as follows: * 455565152535 * 123456 * * * Done. *I
* Entries in a list have positions that begin with 1. * eauthor Frank M. Carrano * dauthor
Timothy M. Henry * aversion 5.0 */ ublic interface ListInterface { /** * Adds a new entry to the
end of this list. * Entries currently in the list are unaffected. * The list's size is increased by 1 . *
Gparam newEntry The object to be added as a new entry. */ public void add( T newEntry); /** *
Adds a new entry at a specified position within this list. * Entries originally at and above the
specified position * are at the next higher position within the list. * The list's size is increased by
1 . * Caparam newPosition An integer that specifies the desired * position of the new entry. *
Caparam newEntry The object to be added as a new entry. * Gathrows
IndexoutofBoundsException if either newPosition < 1 or newPosition > */ getLength ()+1.
public void add(int newPosition, T newEntry); /*** * Removes the entry at a given position from
this list. * Entries originally at positions higher than the given * position are at the next lower
position within the list, * and the list's size is decreased by 1 . * eparam givenPosition An integer
that indicates the position of the entry to be removed. * ereturn A reference to the removed entry.
* athrows IndexOutofBoundsException if either * givenPosition <1 or givenPosition > */
getLength(). public T remove(int givenPosition); /** Removes all entries from this list. */ public
void clear(); /** * Replaces the entry at a given position in this list. * Gparam givenPosition An
integer that indicates the position of * the entry to be replaced. * eparam newEntry The object
that will replace the entry at the * areturn The original position givenPosition. * athrows
Index0utal entry that was replaced. * givenPosition <1 or givenPosition > */ givenPosition < 1
or givenPosition > getLength(). public T replace(int givenPosition, T newEntry); / ** Retrieves
the entry at a given position in this list. * @param givenPosition An integer that indicates the
position of the desired entry. * areturn A reference to the indicated entry. * Gthrows
Index0ut0fBoundsException if either givenPosition < 1 or givenPosition > */ getLength ( ).
public T getEntry(int givenPosition); /** * Retrieves all entries that are in this list in the order in
which * they occur in the list. * Greturn A newly allocated array of all the entries in the list. * If
the list is empty, the returned array is empty. public T[] toArray(); /*** * Sees whether this list
contains a given entry. * eparam anEntry The object that is the desired entry. * Greturn True if
the list contains anEntry, or false if not. */ public boolean contains ( T anEntry); /*** * Gets the
length of this list. * areturn The integer number of entries currently in the list. public int
getLength(); /** * Sees whether this list is empty. * ereturn True if the list is empty, or false if
not. * a public boolean isEmpty(); // end ListInterface

More Related Content

Similar to PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf (20)

Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
annaelctronics
 
please i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfplease i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdf
ezonesolutions
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
arrowmobile
 
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdfLabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
fantasiatheoutofthef
 
Note- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docxNote- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docx
VictorzH8Bondx
 
Note- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfNote- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdf
Stewart29UReesa
 
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
 The MyLinkedList class used in Listing 24.6 is a one-way directional .docx The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
Komlin1
 
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdfCopy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
facevenky
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
babitasingh698417
 
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
  import java.util.Iterator; import java.util.NoSuchElementException; .pdf  import java.util.Iterator; import java.util.NoSuchElementException; .pdf
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
deepakangel
 
There are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdfThere are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdf
aamousnowov
 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfpublic class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
accostinternational
 
Solve using java and using this Singly linked list classpublic cl.pdf
Solve using java and using this Singly linked list classpublic cl.pdfSolve using java and using this Singly linked list classpublic cl.pdf
Solve using java and using this Singly linked list classpublic cl.pdf
aloeplusint
 
Fix my codeCode.pdf
Fix my codeCode.pdfFix my codeCode.pdf
Fix my codeCode.pdf
Conint29
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
xlynettalampleyxc
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
info430661
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdf
fmac5
 
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
Note- Can someone help me with the public boolean isEmpty()- public bo.pdfNote- Can someone help me with the public boolean isEmpty()- public bo.pdf
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
Augstore
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
mail931892
 
For each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdfFor each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdf
dhavalbl38
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
annaelctronics
 
please i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfplease i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdf
ezonesolutions
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
arrowmobile
 
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdfLabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
fantasiatheoutofthef
 
Note- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docxNote- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docx
VictorzH8Bondx
 
Note- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfNote- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdf
Stewart29UReesa
 
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
 The MyLinkedList class used in Listing 24.6 is a one-way directional .docx The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
Komlin1
 
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdfCopy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
facevenky
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
babitasingh698417
 
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
  import java.util.Iterator; import java.util.NoSuchElementException; .pdf  import java.util.Iterator; import java.util.NoSuchElementException; .pdf
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
deepakangel
 
There are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdfThere are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdf
aamousnowov
 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfpublic class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
accostinternational
 
Solve using java and using this Singly linked list classpublic cl.pdf
Solve using java and using this Singly linked list classpublic cl.pdfSolve using java and using this Singly linked list classpublic cl.pdf
Solve using java and using this Singly linked list classpublic cl.pdf
aloeplusint
 
Fix my codeCode.pdf
Fix my codeCode.pdfFix my codeCode.pdf
Fix my codeCode.pdf
Conint29
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
xlynettalampleyxc
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
info430661
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdf
fmac5
 
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
Note- Can someone help me with the public boolean isEmpty()- public bo.pdfNote- Can someone help me with the public boolean isEmpty()- public bo.pdf
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
Augstore
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
mail931892
 
For each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdfFor each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdf
dhavalbl38
 

More from climatecontrolsv (11)

Required is a project that seeks to develop a program that check.pdf
Required is a project that seeks to develop a program that check.pdfRequired is a project that seeks to develop a program that check.pdf
Required is a project that seeks to develop a program that check.pdf
climatecontrolsv
 
Question 1A Python list isset of items.an unorderedan ordere.pdf
Question 1A Python list isset of items.an unorderedan ordere.pdfQuestion 1A Python list isset of items.an unorderedan ordere.pdf
Question 1A Python list isset of items.an unorderedan ordere.pdf
climatecontrolsv
 
Question 1A Python list is ��.. set of items.an unorderedan or.pdf
Question 1A Python list is ��.. set of items.an unorderedan or.pdfQuestion 1A Python list is ��.. set of items.an unorderedan or.pdf
Question 1A Python list is ��.. set of items.an unorderedan or.pdf
climatecontrolsv
 
Principles of Insurance Chapter 3 Exercise 1 Name of student Regist.pdf
Principles of Insurance Chapter 3 Exercise 1 Name of student Regist.pdfPrinciples of Insurance Chapter 3 Exercise 1 Name of student Regist.pdf
Principles of Insurance Chapter 3 Exercise 1 Name of student Regist.pdf
climatecontrolsv
 
Please use R studiodata13.txtX Y7.04948502035051 4.37962324700.pdf
Please use R studiodata13.txtX Y7.04948502035051 4.37962324700.pdfPlease use R studiodata13.txtX Y7.04948502035051 4.37962324700.pdf
Please use R studiodata13.txtX Y7.04948502035051 4.37962324700.pdf
climatecontrolsv
 
Please help me what is the best answer for this. (Organizational Beh.pdf
Please help me what is the best answer for this. (Organizational Beh.pdfPlease help me what is the best answer for this. (Organizational Beh.pdf
Please help me what is the best answer for this. (Organizational Beh.pdf
climatecontrolsv
 
Please help this code is supposed to evaluate current node state and i.pdf
Please help this code is supposed to evaluate current node state and i.pdfPlease help this code is supposed to evaluate current node state and i.pdf
Please help this code is supposed to evaluate current node state and i.pdf
climatecontrolsv
 
Please IRAC this brief. Terrance and Barbara Moser were married on O.pdf
Please IRAC this brief. Terrance and Barbara Moser were married on O.pdfPlease IRAC this brief. Terrance and Barbara Moser were married on O.pdf
Please IRAC this brief. Terrance and Barbara Moser were married on O.pdf
climatecontrolsv
 
Please help me fix this code! will upvote. The code needs to produce .pdf
Please help me fix this code! will upvote.  The code needs to produce .pdfPlease help me fix this code! will upvote.  The code needs to produce .pdf
Please help me fix this code! will upvote. The code needs to produce .pdf
climatecontrolsv
 
PART 1Net present value represents the difference between the pres.pdf
PART 1Net present value represents the difference between the pres.pdfPART 1Net present value represents the difference between the pres.pdf
PART 1Net present value represents the difference between the pres.pdf
climatecontrolsv
 
Please create a context diagram of the following housing system Y.pdf
Please create a context diagram of the following housing system Y.pdfPlease create a context diagram of the following housing system Y.pdf
Please create a context diagram of the following housing system Y.pdf
climatecontrolsv
 
Required is a project that seeks to develop a program that check.pdf
Required is a project that seeks to develop a program that check.pdfRequired is a project that seeks to develop a program that check.pdf
Required is a project that seeks to develop a program that check.pdf
climatecontrolsv
 
Question 1A Python list isset of items.an unorderedan ordere.pdf
Question 1A Python list isset of items.an unorderedan ordere.pdfQuestion 1A Python list isset of items.an unorderedan ordere.pdf
Question 1A Python list isset of items.an unorderedan ordere.pdf
climatecontrolsv
 
Question 1A Python list is ��.. set of items.an unorderedan or.pdf
Question 1A Python list is ��.. set of items.an unorderedan or.pdfQuestion 1A Python list is ��.. set of items.an unorderedan or.pdf
Question 1A Python list is ��.. set of items.an unorderedan or.pdf
climatecontrolsv
 
Principles of Insurance Chapter 3 Exercise 1 Name of student Regist.pdf
Principles of Insurance Chapter 3 Exercise 1 Name of student Regist.pdfPrinciples of Insurance Chapter 3 Exercise 1 Name of student Regist.pdf
Principles of Insurance Chapter 3 Exercise 1 Name of student Regist.pdf
climatecontrolsv
 
Please use R studiodata13.txtX Y7.04948502035051 4.37962324700.pdf
Please use R studiodata13.txtX Y7.04948502035051 4.37962324700.pdfPlease use R studiodata13.txtX Y7.04948502035051 4.37962324700.pdf
Please use R studiodata13.txtX Y7.04948502035051 4.37962324700.pdf
climatecontrolsv
 
Please help me what is the best answer for this. (Organizational Beh.pdf
Please help me what is the best answer for this. (Organizational Beh.pdfPlease help me what is the best answer for this. (Organizational Beh.pdf
Please help me what is the best answer for this. (Organizational Beh.pdf
climatecontrolsv
 
Please help this code is supposed to evaluate current node state and i.pdf
Please help this code is supposed to evaluate current node state and i.pdfPlease help this code is supposed to evaluate current node state and i.pdf
Please help this code is supposed to evaluate current node state and i.pdf
climatecontrolsv
 
Please IRAC this brief. Terrance and Barbara Moser were married on O.pdf
Please IRAC this brief. Terrance and Barbara Moser were married on O.pdfPlease IRAC this brief. Terrance and Barbara Moser were married on O.pdf
Please IRAC this brief. Terrance and Barbara Moser were married on O.pdf
climatecontrolsv
 
Please help me fix this code! will upvote. The code needs to produce .pdf
Please help me fix this code! will upvote.  The code needs to produce .pdfPlease help me fix this code! will upvote.  The code needs to produce .pdf
Please help me fix this code! will upvote. The code needs to produce .pdf
climatecontrolsv
 
PART 1Net present value represents the difference between the pres.pdf
PART 1Net present value represents the difference between the pres.pdfPART 1Net present value represents the difference between the pres.pdf
PART 1Net present value represents the difference between the pres.pdf
climatecontrolsv
 
Please create a context diagram of the following housing system Y.pdf
Please create a context diagram of the following housing system Y.pdfPlease create a context diagram of the following housing system Y.pdf
Please create a context diagram of the following housing system Y.pdf
climatecontrolsv
 

Recently uploaded (20)

Post Exam Fun(da)- a General under-25 quiz, Prelims and Finals
Post Exam Fun(da)- a General  under-25 quiz, Prelims and FinalsPost Exam Fun(da)- a General  under-25 quiz, Prelims and Finals
Post Exam Fun(da)- a General under-25 quiz, Prelims and Finals
Pragya - UEM Kolkata Quiz Club
 
Intervene with Precision: Zooming In as a Leader Without Micromanaging
Intervene with Precision: Zooming In as a Leader Without MicromanagingIntervene with Precision: Zooming In as a Leader Without Micromanaging
Intervene with Precision: Zooming In as a Leader Without Micromanaging
victoriamangiantini1
 
Leveraging AI to Streamline Operations for Nonprofits [05.20.2025].pdf
Leveraging AI to Streamline Operations for Nonprofits [05.20.2025].pdfLeveraging AI to Streamline Operations for Nonprofits [05.20.2025].pdf
Leveraging AI to Streamline Operations for Nonprofits [05.20.2025].pdf
TechSoup
 
Decision Tree-ID3,C4.5,CART,Regression Tree
Decision Tree-ID3,C4.5,CART,Regression TreeDecision Tree-ID3,C4.5,CART,Regression Tree
Decision Tree-ID3,C4.5,CART,Regression Tree
Global Academy of Technology
 
ALL BENGAL U25 QUIZ LEAGUE 2.0 SET BY SKP.pptx
ALL BENGAL U25 QUIZ LEAGUE 2.0 SET BY SKP.pptxALL BENGAL U25 QUIZ LEAGUE 2.0 SET BY SKP.pptx
ALL BENGAL U25 QUIZ LEAGUE 2.0 SET BY SKP.pptx
Sourav Kr Podder
 
How to Manage Customer Info from POS in Odoo 18
How to Manage Customer Info from POS in Odoo 18How to Manage Customer Info from POS in Odoo 18
How to Manage Customer Info from POS in Odoo 18
Celine George
 
the dynastic history of Paramaras of Malwa
the dynastic history of Paramaras of Malwathe dynastic history of Paramaras of Malwa
the dynastic history of Paramaras of Malwa
PrachiSontakke5
 
The Pedagogy We Practice: Best Practices for Critical Instructional Design
The Pedagogy We Practice: Best Practices for Critical Instructional DesignThe Pedagogy We Practice: Best Practices for Critical Instructional Design
The Pedagogy We Practice: Best Practices for Critical Instructional Design
Sean Michael Morris
 
Management of head injury in children.pdf
Management of head injury in children.pdfManagement of head injury in children.pdf
Management of head injury in children.pdf
sachin7989
 
Letter to Secretary Linda McMahon from U.S. Senators
Letter to Secretary Linda McMahon from U.S. SenatorsLetter to Secretary Linda McMahon from U.S. Senators
Letter to Secretary Linda McMahon from U.S. Senators
Mebane Rash
 
NA FASE REGIONAL DO TL – 1.º CICLO. .
NA FASE REGIONAL DO TL – 1.º CICLO.     .NA FASE REGIONAL DO TL – 1.º CICLO.     .
NA FASE REGIONAL DO TL – 1.º CICLO. .
Colégio Santa Teresinha
 
Salinity Resistance in Plants.Rice plant
Salinity Resistance in Plants.Rice plantSalinity Resistance in Plants.Rice plant
Salinity Resistance in Plants.Rice plant
aliabatool11
 
Regression Analysis-Machine Learning -Different Types
Regression Analysis-Machine Learning -Different TypesRegression Analysis-Machine Learning -Different Types
Regression Analysis-Machine Learning -Different Types
Global Academy of Technology
 
Electronics Engineering Assignment Help Guide – Expert Support for Students
Electronics Engineering Assignment Help Guide – Expert Support for StudentsElectronics Engineering Assignment Help Guide – Expert Support for Students
Electronics Engineering Assignment Help Guide – Expert Support for Students
online college homework help
 
TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...
TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...
TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...
TechSoup
 
The Splitting of the Moon (Shaqq al-Qamar).pdf
The Splitting of the Moon (Shaqq al-Qamar).pdfThe Splitting of the Moon (Shaqq al-Qamar).pdf
The Splitting of the Moon (Shaqq al-Qamar).pdf
Mirza Gazanfar Ali Baig
 
Basic principles involved in the traditional systems of medicine, Chapter 7,...
Basic principles involved in the traditional systems of medicine,  Chapter 7,...Basic principles involved in the traditional systems of medicine,  Chapter 7,...
Basic principles involved in the traditional systems of medicine, Chapter 7,...
ARUN KUMAR
 
How to Manage Allow Ship Later for Sold Product in odoo Point of Sale
How to Manage Allow Ship Later for Sold Product in odoo Point of SaleHow to Manage Allow Ship Later for Sold Product in odoo Point of Sale
How to Manage Allow Ship Later for Sold Product in odoo Point of Sale
Celine George
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-21-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-21-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-21-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-21-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Statement by Linda McMahon on May 21, 2025
Statement by Linda McMahon on May 21, 2025Statement by Linda McMahon on May 21, 2025
Statement by Linda McMahon on May 21, 2025
Mebane Rash
 
Post Exam Fun(da)- a General under-25 quiz, Prelims and Finals
Post Exam Fun(da)- a General  under-25 quiz, Prelims and FinalsPost Exam Fun(da)- a General  under-25 quiz, Prelims and Finals
Post Exam Fun(da)- a General under-25 quiz, Prelims and Finals
Pragya - UEM Kolkata Quiz Club
 
Intervene with Precision: Zooming In as a Leader Without Micromanaging
Intervene with Precision: Zooming In as a Leader Without MicromanagingIntervene with Precision: Zooming In as a Leader Without Micromanaging
Intervene with Precision: Zooming In as a Leader Without Micromanaging
victoriamangiantini1
 
Leveraging AI to Streamline Operations for Nonprofits [05.20.2025].pdf
Leveraging AI to Streamline Operations for Nonprofits [05.20.2025].pdfLeveraging AI to Streamline Operations for Nonprofits [05.20.2025].pdf
Leveraging AI to Streamline Operations for Nonprofits [05.20.2025].pdf
TechSoup
 
ALL BENGAL U25 QUIZ LEAGUE 2.0 SET BY SKP.pptx
ALL BENGAL U25 QUIZ LEAGUE 2.0 SET BY SKP.pptxALL BENGAL U25 QUIZ LEAGUE 2.0 SET BY SKP.pptx
ALL BENGAL U25 QUIZ LEAGUE 2.0 SET BY SKP.pptx
Sourav Kr Podder
 
How to Manage Customer Info from POS in Odoo 18
How to Manage Customer Info from POS in Odoo 18How to Manage Customer Info from POS in Odoo 18
How to Manage Customer Info from POS in Odoo 18
Celine George
 
the dynastic history of Paramaras of Malwa
the dynastic history of Paramaras of Malwathe dynastic history of Paramaras of Malwa
the dynastic history of Paramaras of Malwa
PrachiSontakke5
 
The Pedagogy We Practice: Best Practices for Critical Instructional Design
The Pedagogy We Practice: Best Practices for Critical Instructional DesignThe Pedagogy We Practice: Best Practices for Critical Instructional Design
The Pedagogy We Practice: Best Practices for Critical Instructional Design
Sean Michael Morris
 
Management of head injury in children.pdf
Management of head injury in children.pdfManagement of head injury in children.pdf
Management of head injury in children.pdf
sachin7989
 
Letter to Secretary Linda McMahon from U.S. Senators
Letter to Secretary Linda McMahon from U.S. SenatorsLetter to Secretary Linda McMahon from U.S. Senators
Letter to Secretary Linda McMahon from U.S. Senators
Mebane Rash
 
Salinity Resistance in Plants.Rice plant
Salinity Resistance in Plants.Rice plantSalinity Resistance in Plants.Rice plant
Salinity Resistance in Plants.Rice plant
aliabatool11
 
Regression Analysis-Machine Learning -Different Types
Regression Analysis-Machine Learning -Different TypesRegression Analysis-Machine Learning -Different Types
Regression Analysis-Machine Learning -Different Types
Global Academy of Technology
 
Electronics Engineering Assignment Help Guide – Expert Support for Students
Electronics Engineering Assignment Help Guide – Expert Support for StudentsElectronics Engineering Assignment Help Guide – Expert Support for Students
Electronics Engineering Assignment Help Guide – Expert Support for Students
online college homework help
 
TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...
TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...
TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...
TechSoup
 
The Splitting of the Moon (Shaqq al-Qamar).pdf
The Splitting of the Moon (Shaqq al-Qamar).pdfThe Splitting of the Moon (Shaqq al-Qamar).pdf
The Splitting of the Moon (Shaqq al-Qamar).pdf
Mirza Gazanfar Ali Baig
 
Basic principles involved in the traditional systems of medicine, Chapter 7,...
Basic principles involved in the traditional systems of medicine,  Chapter 7,...Basic principles involved in the traditional systems of medicine,  Chapter 7,...
Basic principles involved in the traditional systems of medicine, Chapter 7,...
ARUN KUMAR
 
How to Manage Allow Ship Later for Sold Product in odoo Point of Sale
How to Manage Allow Ship Later for Sold Product in odoo Point of SaleHow to Manage Allow Ship Later for Sold Product in odoo Point of Sale
How to Manage Allow Ship Later for Sold Product in odoo Point of Sale
Celine George
 
Statement by Linda McMahon on May 21, 2025
Statement by Linda McMahon on May 21, 2025Statement by Linda McMahon on May 21, 2025
Statement by Linda McMahon on May 21, 2025
Mebane Rash
 

PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf

  • 1. PROBLEM STATEMENT: In this assignment, you will complete DoubleEndedList.java that implements the ListInterface as well as an interface called DoubleEndedInterface which represents the list's entries by using a chain of nodes that has both a head reference and a tail reference. Be sure to read through the code and understand the implementation. WHAT IS PROVIDED: - A driver class to test your code. You should not modify this file! - A list interface (ListInterface.java) - A double ended interface (DoubleEndedInterface.java) - An incomplete DoubleEndedList class (DoubleEndedList.java) WHAT YOU NEED TO DO: 4. Complete the DoubleEndedList class 4. Run the driver and make sure your output is exactly the same as mine (at the bottom of Driver.java) } // end else numberofEntries--; else throw new IndexOut0fBoundsException("Illegal position given to remove operation."); return result; // Return removed entry }//endreturnreve public T replace(int givenPosition, T newEntry) { T replace(int givenPosition, T newEntry) { if ((givenPosition >=1)&& (givenPosition <= numberOfEntries)) { // Assertion: The list is not empty Node desiredNode = getNodeAt (givenPosition); ToriginalEntry = desiredNode.getData(); desiredNode.setData(newEntry); return originalEntry; f // end if else throw new IndexOut0fBoundsException("Illegal position given to replace operation."); replace if (( givenPosition >=1)&& (givenPosition <= number0fEntries)) { // Assertion: The list is not empty Node desiredNode = getNodeAt ( givenPosition); T originalEntry = desiredNode. getData( ); desiredNode.setData(newEntry); return originalentry; } // end if throw new Index0ut0fBoundsException("Illegal position given to replace operation."); } // end replace public T getEntry(int givenPosition) { if ((givenPosition >=1) && (givenPosition < = number0fEntries ) ) { // Assertion: The list is not empty return getNodeAt (givenPosition). getData(); else // end if throw new IndexOut0fBoundsException("Illegal position given to getEntry operation."); } // end getEntry public boolean contains ( T anEntry) { boolean found = false; Node currentNode = firstNode; while (!found && (currentNode != null)) { if (anEntry.equals (currentNode.getData())) else found = true; } // end while currentNode = currentNode. getNextNode () ; return found; } // end contains public int getLength() { return
  • 2. numberofEntries; } // end getLength public boolean isEmpty() { return number0fEntries ==0; } // end isEmpty public T[] toArray() { // The cast is safe because the new array contains null entries aSuppressWarnings ("unchecked") T[] result =(T[]) new 0bject [numberofEntries]; // Unchecked cast int index =0; Node currentNode = firstNode; while ((index < numberOfEntries) && (currentNode != null)) & result [ index ]= currentNode. getData () ; currentNode = currentNode.getNextNode ( ); index++; 3 // end while return result; 3 // end toArray // Returns a reference to the node at a given position. // Precondition: List is not empty; 1<= givenPosition < = numberofEntries. // Assertion: (firstNode != null) and (1<= givenPosition) and (givenPosition <= // numberofEntries) Node currentNode = firstNode; if (givenPosition == numberofEntries) currentNode = lastNode; else if (givenPosition >1 ) // Traverse the chain to locate the desired node for (int counter =1; counter < givenPosition; counter++) currentNode = currentNode. getNextNode () ; assert currentNode != null; return currentNode; } // end getNodeAt private class Node { private T data; // Data portion private Node next; // Next to next node data = dataPortion; } // end constructor data = dataPortion; } // end constructor private T getData() { } // end return data; private void setData( T newData) { data = newData; } // end setData private Node getNextNode() { return next; } // end getNextNode private void setNextNode(Node nextNode) { next = nextNode; } // end setNextNode } // end Node 1** A class that implements the ADT double-ended list by using a chain of nodes. * The chain has both a head reference and a tail reference. * Position numbers begin with 1 . * Q eauthor Frank M. Carrano * dauthor Joseph Erickson */ aversion 5.0 public class DoubleEndedList implements ListInterface , DoubleEndedInterface { private Node firstNode; // Head reference to first node private Node lastNode; // Ta private int numberofEntries; public DoubleEndedList() { } clear (); // ============= // ADDED METHODS: public void addFirst(T newEntry) f } // end addFirst public void addLast (T newEntry) { } // end addLast public T removefirst() { } // end removefirst public T removelast() { } // end removelast public T getFirst() { } // end getFirst public T getLast () { } // end getLast public void moveToEnd() { } // end moveToEnd // ====================== public final void clear() firstNode = null; lastNode = null; numberOfEntries =0 } // end clear public void add ( T newEntry) { Node newNode = new Node (newEntry); // Create new node if (isEmpty()) else firstNode = newNode; las tNode.
  • 3. setNextNode (newNode); lastNode = newNode; numberOfEntries++; 3 // end add if (( newPosition >=1)&& (newPosition <= numberofEntries +1)){ Node newNode = new Node (newEntry); if (isEmpty()) firstNode = newNode lastNode = newNode; }// end if else if (newPosition =1 ) { newNode. SetNextNodel first Node = newNode; 3 // end else if (newPosition == numberOfEntries +1 ) { lastNode. setNextNode (newNode); last Node = newNode; } // end else { Node nodeBefore = getNodeAt ( newPosition -1); Node nodeAfter = nodeBefore.getNextNode () newNode. setNextNode (nodeAfter); 3 // end else } // end if else } // end add throw new IndexOut0fBoundsException("Illegal position given to add operation."); public T remove(int givenPosition) { T result = null; // Return value if ((givenPosition >=1)&& (givenPosition <= number0fEntries)) { // Assertion: The list is not empty result = firstNode. getData ();// Save entry to be removed firstNode = firstNode.getNextNode( ); if (numberofentries =1 ) } // end if lastNode = null; // Solitary entry was removed else // Case 2: givenPosition > 1 Node nodeBefore = getNodeAt (givenPosition -1); Node nodeToRemove = nodeBefore. getNextNode (); Node nodeAfter = nodeToRemove. getNextNode (); Node nodeAfter = nodeToRemove.getNextNode (); nodeBefore.setNextNode(nodeAfter); // Disconnect the node to be removed result = nodeToRemove.getData(); // Save entry to be removed if (givenPosition == numberofentries) lastNode = nodeBefore; // Last node was removed } // end else numberofEntries--; else throw new Indexout0fBoundsException("Illegal position given to remove operation."); return result; // Return removed entry remove } // end remove public T replace(int givenPosition, T newEntry) { venPosition >=1)&& (givenPosition <= numberofentries) ) { Node desiredNode = getNodeAt (givenPosition); ToriginalEntry = desiredNode.getData( ); return originalData (newEntry); } // end if throw new IndexOut0fBoundsException("Illegal position given to replace operation."); An interface for a collection that has a first entry and a last entry. @author Frank M. Carrano Qversion 5.0 / ablic interface DoubleEndedInterface {/ * Adds a new entry to the beginning of this collection. * @param newEntry The object to be added as a new entry. 1 public void addFirst(T newEntry); /** * Adds a new entry to the end of this collection. * Qparam newEntry The object to be added as a new entry. / public void addLast( T newEntry); /** * Removes and returns the first entry in this collection. * areturn A reference to the removed entry or null, if * the list was empty. / public T removefirst(); /** * Removes and returns the last entry in this collection. * Qreturn A reference to the removed entry or null, if * the list was empty. / public T removelast(); /** * Retrieves the first entry in this collection. * areturn A reference to the first entry or null, if * the list is empty. 1 public T getFirst(); /** * Retrieves the last entry in this collection. * Qreturn A reference to the last entry or null, if * the list is empty. / public T getLast(); /** Moves the first entry in this collection to the end of the list. */ public void
  • 4. moveToEnd(); // end DoubleEndedInterface ver that demonstrates the class DoubleEndedList. thest only the additional methods, since the methods or Frank M. Carrano ion 5.0 lass Driver { lass Driver { public static void main(String[] args) { System.out.println("Create an empty list."); System. out.print ln("Create an empty list."); DoubleEndedList < String > myList = new DoubleEndedList <(); System.out.println("List should be empty; isEmpty() returns " + myList.isEmpty() + "."); System.out.print ln("nTesting addFirst:"); myList.addFirst ("15"); myList. addFirst (" 25 ") mylist.addFirst (" 45) System.out.println("List should contain 453525 15."); myList.clear(); mylist.clear(); myList. addLast ("15"); myList.addLast ("35") myList.addLast (" 45) myList.addLast ("55"); myList. addLast ("65"); displaylist (myList); System.out.print ln("nTesting removeFirst with previous list:"); System.out.println("removeFirst (): " + myList. removeFirst ()); System. out.println("nList should containn45 5565 "); displayList (myList); System. out.println("removefirst(): " + myList. removeFirst()); System. out.println("removefirst(): " + myList. removefirst()); System. out.println("List should be empty; isEmpty() returns" + myList.isEmpty() + "."); myList.clear(); myList. addLast ("15"); myList.addLast (" 25 ") myList. addLast ("45"); myList. addLast ("55"); System.out.println("List should contain 1525354555 65."); displaylist (myList); System.out.println("removeLast (): " + myList.removeLast()); System.out.println("removeLast (): " + myList.removeLast ()); System. out.print ln ("removeLast (): " + myList. removeLast ()) System. out.print ln ("removeLast (): " + mylist.removelast ()); System.out.println("nList should contain n15"); displaylist (myList); ( ) System.out.print ln("nTesting getFirst and getlast with the following list:"); myList.clear() myList.addLast ("15"); myList.addLast (" 25 "); myList. addLast ("35"); myList. addLast (" 55) myList.addLast ("65"); displayList (myList): System.out.println("Retrieving the first entry : returns " + myList.getFirst()); System.out.print ln("nTesting moveToEnd with the following list:"); displayList (myList); myList. moveToEnd () System. out.println("After moveToEnd, the list is:"); displaylist (myList); myList. moveToEnd ( ) System.out.println("After moveToEnd, the list is:"); displaylist (myList); myList. moveToEnd ( ) System.out.println("After moveToEnd, the list is:"); displaylist (mylist); System. out.print ln ("nnDone."); public static void displayList(ListInterface aList) { System.out.println("The list contains " + aList.getLength() + "string(s), as follows:"); Object [] listArray = aList. toArray(); for (int index =0; index < listarray. length; index++) { } // end for System.out.print ln(); for (int position =1; position <= listarray. length; position++) { if (position < 10) else System.out.print(" " + position); System.out.print (position); System.out.print(" "); }//endfor System.out.print ln(); H/ end Driver e an empty list. should be empty; isEmpty() returns true. son list. ng addFirst: should contain 45352515 ist contains 4 string(s), as follows: 4 ng addlast with the following list: should contain
  • 5. 152535455565. ist contains 456 * Testing removefirst with previous list: * removefirst(): 15 * removeFirst(): 25 * removeFirst(): 35 * List should contain * 455565 * The list contains 3 string(s), as follows: * 455565 * 123 * removeFirst(): 45 * removeFirst(): 55 * removeFirst(): 65 * removefirst(): null * List should be empty; isEmpty() returns true. * * Testing removelast with the following list: * List should contain 152535455565 . * The list contains 6 string(s), as follows: * 152535455565 * 123456 * removeLast (): 65 * removelast (): 55 * removelast (): 45 * removelast (): 35 * removeLast (): 25 * List should contain * 15 * The list contains 1 string(s), as follows: * 15 * 1 * removelast (): 15 * removelast (): null * List should be empty; isEmpty() returns true. * Testing getFirst and getlast with the following list: * The list contains 6 string(s), as follows: * 152535455565 * 123456 * Retrieving the first entry : returns 15 * Retrieving the last entry : returns 65 * Testing moveToEnd with the following list: * The list contains 6 string(s), as follows: * 152535455565 * 123456 * After moveToEnd, the list is: * The list contains 6 string(s), as follows: * 253545556515 * 123456 * After moveToEnd, the list is: * The list contains 6 string(s), as follows: * 354555651525 * 123456 * After moveToEnd, the list is: * The list contains 6 string(s), as follows: * 455565152535 * 123456 * * * Done. *I * Entries in a list have positions that begin with 1. * eauthor Frank M. Carrano * dauthor Timothy M. Henry * aversion 5.0 */ ublic interface ListInterface { /** * Adds a new entry to the end of this list. * Entries currently in the list are unaffected. * The list's size is increased by 1 . * Gparam newEntry The object to be added as a new entry. */ public void add( T newEntry); /** * Adds a new entry at a specified position within this list. * Entries originally at and above the specified position * are at the next higher position within the list. * The list's size is increased by 1 . * Caparam newPosition An integer that specifies the desired * position of the new entry. * Caparam newEntry The object to be added as a new entry. * Gathrows IndexoutofBoundsException if either newPosition < 1 or newPosition > */ getLength ()+1. public void add(int newPosition, T newEntry); /*** * Removes the entry at a given position from this list. * Entries originally at positions higher than the given * position are at the next lower position within the list, * and the list's size is decreased by 1 . * eparam givenPosition An integer that indicates the position of the entry to be removed. * ereturn A reference to the removed entry. * athrows IndexOutofBoundsException if either * givenPosition <1 or givenPosition > */ getLength(). public T remove(int givenPosition); /** Removes all entries from this list. */ public void clear(); /** * Replaces the entry at a given position in this list. * Gparam givenPosition An integer that indicates the position of * the entry to be replaced. * eparam newEntry The object that will replace the entry at the * areturn The original position givenPosition. * athrows
  • 6. Index0utal entry that was replaced. * givenPosition <1 or givenPosition > */ givenPosition < 1 or givenPosition > getLength(). public T replace(int givenPosition, T newEntry); / ** Retrieves the entry at a given position in this list. * @param givenPosition An integer that indicates the position of the desired entry. * areturn A reference to the indicated entry. * Gthrows Index0ut0fBoundsException if either givenPosition < 1 or givenPosition > */ getLength ( ). public T getEntry(int givenPosition); /** * Retrieves all entries that are in this list in the order in which * they occur in the list. * Greturn A newly allocated array of all the entries in the list. * If the list is empty, the returned array is empty. public T[] toArray(); /*** * Sees whether this list contains a given entry. * eparam anEntry The object that is the desired entry. * Greturn True if the list contains anEntry, or false if not. */ public boolean contains ( T anEntry); /*** * Gets the length of this list. * areturn The integer number of entries currently in the list. public int getLength(); /** * Sees whether this list is empty. * ereturn True if the list is empty, or false if not. * a public boolean isEmpty(); // end ListInterface