SlideShare a Scribd company logo
Implement the interface you wrote for Lab B (EntryWayListInterface). As a reminder,
EntryWayListInterface allows the user to access to list elements only through the beginning and
end of the list.
Your implementation can use either an expandable array or linked nodes- it is your choice. You
can decide what instance variables are needed. You must implement every method from the
interface. Make sure to account for special conditions such as empty lists and singleton lists.
Note: your instance data variable should be either a) an array or b) one or more nodes. It should
not be an AList or LList object or an ArrayList object.
Your implementation must:
compile
contain these implemented methods:
insertHead
insertTail
deleteHead
deleteTail
display
contains
isEmpty
isFull
Also create a driver program to test your implementation. The driver program will operate from
the client perspective. Your driver program should:
display an empty list
add five entries to the list- some at the head and some at the tail
display the list
remove the first entry
remove the last entry
display the list
test to see if elements are in the list (test one element that is in the list and one that is not)
remove the last three elements in the list
try to remove an element from the empty list
Write a second class to implement EntryWayListInterface. Instead of using an array or linked
nodes, use either an AList or LList object as your instance data variable. In this way, you are
using an existing data type (AList or LList) to implement a new data type
(EntryWayListInterface). Inside the methods of this class, invoke methods on the AList or LList
object to accomplish the task.
/** An interface for the ADT list.
Entries in a list have positions that begin with 1.
* Accesses only entries that are the head or tail of the list.
*/
public interface EntryWayInterface {
/** Adds a new entry to this list T.
* @param newEntry The object to be added as a new entry.
* @return True if the addition is successful, or false if not. */
public boolean insertHead(T newEntry);
/** Deletes a new entry to this list T.
* @param newEntry The object to be added as a new entry.
* @return True if the addition is successful, or false if not. */
public boolean insertTail(T newEntry);
/** Deletes the object that is at the head of list T.
* @return the object that has been deleted and returns
* null if no object was deleted.
*/
public T deleteHead();
/** Deletes the object that is at the tail of list T.
* @return the object that has been deleted or else return null
* if no object was deleted.
*/
public T deleteTail();
/** Displays the contents of the list T.
*/
public void display();
/** See whether this list T contains a given entry.
* @param anEntry The object that is the desired entry.
* @return the position of the entry that was found.
* else returns false if the object is not in the list.
*/
public int contains(T anEntry);
/** Sees whether this list is empty.
* @return True if the list is empty, or false if not. */
public boolean isEmpty();
/** Sees whether this list is full.
* @return True if the list is full, or false if not. */
public boolean isFull();
}//end EntryWayInterface
Solution
public class LEntryWayList implements EntryWayListInterface {
private Node firstNode;
private Node lastNode;
private int length;
public LEntryWayList() {
clear();
}
public final void clear() {
firstNode = null;
lastNode = null;
length = 0;
}
/**
* Task: Places a new object at beginning of list
*
* @param newEntry is a valid object
* @return true if insert is successful; false otherwise
*/
public boolean insertHead(T newEntry) {
Node newNode = new Node(newEntry);
if (isEmpty()) {
firstNode = newNode;
lastNode = newNode;
} else {
newNode.next = firstNode;
firstNode = newNode;
}
length++;
return true;
}
/**
* Task: Places a new object at the end of the list
*
* @param newEntry is a valid object
* @return true if insertion successful; false otherwise
*/
public boolean insertTail(T newEntry) {
Node newNode = new Node(newEntry);
if (isEmpty()) {
firstNode = newNode;
} else {
lastNode.next = newNode;
}
lastNode = newNode;
length++;
return true;
}
/**
* Task: delete the object at the beginning of the list
*
* @return the object that has been deleted
*/
public T deleteHead() {
T result = null;
if (length >= 1) {
assert !isEmpty();
if (length == 1) {
result = firstNode.data;
firstNode = null;
lastNode = null;
} else {
result = firstNode.data;
firstNode = firstNode.next;
}
length--;
}
return result;
}
/**
* Task: delete the object at the end of the list
*
* @return the object that has been deleted, or null if the list was empty
*/
public T deleteTail() {
T result = null;
if (length >= 1) {
assert !isEmpty();
if (length == 1) {
result = firstNode.data;
firstNode = null;
lastNode = null;
} else {
Node nodeBefore = getNodeAt(length - 1);
Node nodeToRemove = nodeBefore.next;
nodeBefore.next = null;
result = nodeToRemove.data;
lastNode = nodeBefore;
}
length--;
}
return result;
}
/**
* Task: display the contents of the list on the console, in order, one per
* line
*/
public void display() {
Node currentNode = firstNode;
while (currentNode != null) {
System.out.println(currentNode.getData());
currentNode = currentNode.getNext();
}
}
/**
* Task: search the list for the given object and return its position in the
* list, or -1 if it's not found
*
* @param anEntry is a valid object to find in the list
* @return the position of the entry that was found, or -1 if it's not found
*/
public int contains(T anEntry) {
int found = 0;
Node currentNode = firstNode;
while (currentNode != null) {
found++;
if (anEntry.equals(currentNode.getData())) {
return found;
} else {
currentNode = currentNode.getNext();
}
}
return -1;
}
/**
* Task: check to see if list is empty
*
* @return true if list is empty, false if list contains one or more
* objects.
*/
public boolean isEmpty() {
boolean result;
if (length == 0) {
assert firstNode == null;
result = true;
} else {
assert firstNode != null;
result = false;
}
return result;
}
/**
* Task: check if list is full
*
* @return true if list is full, false if list has space for more objects
*/
public boolean isFull() {
return false; // Linked lists always return false
}
private Node getNodeAt(int givenPosition) {
assert !isEmpty()
&& ((1 <= givenPosition) && (givenPosition <= length));
Node currentNode = firstNode;
for (int counter = 1; counter < givenPosition; counter++) {
currentNode = currentNode.getNext();
}
assert currentNode != null;
return currentNode;
}
private class Node {
private T data;
private Node next;
private Node(T dataPortion) {
data = dataPortion;
next = null;
}
private Node(T dataPortion, Node nextNode) {
data = dataPortion;
next = nextNode;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public Node getNext() {
return next;
}
public void setNext(Node next) {
this.next = next;
}
}
public static void main(String []args){
LEntryWayList l = new LEntryWayList();
l.display();
}
}

More Related Content

Similar to Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf

Please complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxPlease complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docx
cgraciela1
 
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
 
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
 
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
 
package ADTs public interface CollectionADTltTgt .pdf
package ADTs public interface CollectionADTltTgt      .pdfpackage ADTs public interface CollectionADTltTgt      .pdf
package ADTs public interface CollectionADTltTgt .pdf
syedabdul78662
 
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
arshin9
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdf
malavshah9013
 
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfPROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
climatecontrolsv
 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfpublic class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
accostinternational
 
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdfHomework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
ezzi97
 
package linkedLists- import java-util-Iterator- --- A class representi.pdf
package linkedLists- import java-util-Iterator- --- A class representi.pdfpackage linkedLists- import java-util-Iterator- --- A class representi.pdf
package linkedLists- import java-util-Iterator- --- A class representi.pdf
arcellzone
 
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
 
Jhtp5 20 Datastructures
Jhtp5 20 DatastructuresJhtp5 20 Datastructures
Jhtp5 20 Datastructuresmartha leon
 
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
 
Describe an algorithm for concatenating two singly linked lists L and.pdf
Describe an algorithm for concatenating two singly linked lists L and.pdfDescribe an algorithm for concatenating two singly linked lists L and.pdf
Describe an algorithm for concatenating two singly linked lists L and.pdf
deepak596396
 
A popular implementation of List is ArrayList- Look up how to instanti.pdf
A popular implementation of List is ArrayList- Look up how to instanti.pdfA popular implementation of List is ArrayList- Look up how to instanti.pdf
A popular implementation of List is ArrayList- Look up how to instanti.pdf
arsarees
 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdf
seoagam1
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
Conint29
 
Array linked list.ppt
Array  linked list.pptArray  linked list.ppt
Array linked list.ppt
Waf1231
 
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdfProblem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
JamesPXNNewmanp
 

Similar to Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf (20)

Please complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxPlease complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docx
 
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
 
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
 
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
 
package ADTs public interface CollectionADTltTgt .pdf
package ADTs public interface CollectionADTltTgt      .pdfpackage ADTs public interface CollectionADTltTgt      .pdf
package ADTs public interface CollectionADTltTgt .pdf
 
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdf
 
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfPROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfpublic class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
 
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdfHomework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
 
package linkedLists- import java-util-Iterator- --- A class representi.pdf
package linkedLists- import java-util-Iterator- --- A class representi.pdfpackage linkedLists- import java-util-Iterator- --- A class representi.pdf
package linkedLists- import java-util-Iterator- --- A class representi.pdf
 
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
 
Jhtp5 20 Datastructures
Jhtp5 20 DatastructuresJhtp5 20 Datastructures
Jhtp5 20 Datastructures
 
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
 
Describe an algorithm for concatenating two singly linked lists L and.pdf
Describe an algorithm for concatenating two singly linked lists L and.pdfDescribe an algorithm for concatenating two singly linked lists L and.pdf
Describe an algorithm for concatenating two singly linked lists L and.pdf
 
A popular implementation of List is ArrayList- Look up how to instanti.pdf
A popular implementation of List is ArrayList- Look up how to instanti.pdfA popular implementation of List is ArrayList- Look up how to instanti.pdf
A popular implementation of List is ArrayList- Look up how to instanti.pdf
 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdf
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
 
Array linked list.ppt
Array  linked list.pptArray  linked list.ppt
Array linked list.ppt
 
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdfProblem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
 

More from rishabjain5053

write a short essay report to describe a topic of your interest rela.pdf
write a short essay report to describe a topic of your interest rela.pdfwrite a short essay report to describe a topic of your interest rela.pdf
write a short essay report to describe a topic of your interest rela.pdf
rishabjain5053
 
Write a C++ program to do the followingProject Name Computer Sho.pdf
Write a C++ program to do the followingProject Name Computer Sho.pdfWrite a C++ program to do the followingProject Name Computer Sho.pdf
Write a C++ program to do the followingProject Name Computer Sho.pdf
rishabjain5053
 
Which statement pertaining to Port Scanning is FALSEA technique use.pdf
Which statement pertaining to Port Scanning is FALSEA technique use.pdfWhich statement pertaining to Port Scanning is FALSEA technique use.pdf
Which statement pertaining to Port Scanning is FALSEA technique use.pdf
rishabjain5053
 
When did almost all animal phyla divergeSolutionAccording to .pdf
When did almost all animal phyla divergeSolutionAccording to .pdfWhen did almost all animal phyla divergeSolutionAccording to .pdf
When did almost all animal phyla divergeSolutionAccording to .pdf
rishabjain5053
 
What is the nipah virus Describe mechanism of infection How is it .pdf
What is the nipah virus Describe mechanism of infection How is it .pdfWhat is the nipah virus Describe mechanism of infection How is it .pdf
What is the nipah virus Describe mechanism of infection How is it .pdf
rishabjain5053
 
What is organizational inertia List some sources of inertia in a co.pdf
What is organizational inertia List some sources of inertia in a co.pdfWhat is organizational inertia List some sources of inertia in a co.pdf
What is organizational inertia List some sources of inertia in a co.pdf
rishabjain5053
 
Use fundamental identities to write tan t sec2t in terms of sint only.pdf
Use fundamental identities to write tan t sec2t in terms of sint only.pdfUse fundamental identities to write tan t sec2t in terms of sint only.pdf
Use fundamental identities to write tan t sec2t in terms of sint only.pdf
rishabjain5053
 
Twenty-five people responded to a questionnaire about what types of p.pdf
Twenty-five people responded to a questionnaire about what types of p.pdfTwenty-five people responded to a questionnaire about what types of p.pdf
Twenty-five people responded to a questionnaire about what types of p.pdf
rishabjain5053
 
The universe began 13 7 billion years ago, is most directly an exa.pdf
The universe began 13 7 billion years ago,  is most directly an exa.pdfThe universe began 13 7 billion years ago,  is most directly an exa.pdf
The universe began 13 7 billion years ago, is most directly an exa.pdf
rishabjain5053
 
The Stevens Company provided $57000 of services on acco.pdf
The Stevens Company provided $57000 of services on acco.pdfThe Stevens Company provided $57000 of services on acco.pdf
The Stevens Company provided $57000 of services on acco.pdf
rishabjain5053
 
The papillae on the tongue that do not contain any taste buds are the.pdf
The papillae on the tongue that do not contain any taste buds are the.pdfThe papillae on the tongue that do not contain any taste buds are the.pdf
The papillae on the tongue that do not contain any taste buds are the.pdf
rishabjain5053
 
QUESTION 13 Which of the following benefits is a component of Social .pdf
QUESTION 13 Which of the following benefits is a component of Social .pdfQUESTION 13 Which of the following benefits is a component of Social .pdf
QUESTION 13 Which of the following benefits is a component of Social .pdf
rishabjain5053
 
Padre, Inc., buys 80 percent of the outstanding common stock of Sier.pdf
Padre, Inc., buys 80 percent of the outstanding common stock of Sier.pdfPadre, Inc., buys 80 percent of the outstanding common stock of Sier.pdf
Padre, Inc., buys 80 percent of the outstanding common stock of Sier.pdf
rishabjain5053
 
Operating Systems Structure1- Explain briefly why the objectives o.pdf
Operating Systems Structure1- Explain briefly why the objectives o.pdfOperating Systems Structure1- Explain briefly why the objectives o.pdf
Operating Systems Structure1- Explain briefly why the objectives o.pdf
rishabjain5053
 
Need help with this java code. fill in lines where needed. Also, not.pdf
Need help with this java code. fill in lines where needed. Also, not.pdfNeed help with this java code. fill in lines where needed. Also, not.pdf
Need help with this java code. fill in lines where needed. Also, not.pdf
rishabjain5053
 
IP has no mechanism for error reporting or error-correcting. ICMPv4 .pdf
IP has no mechanism for error reporting or error-correcting. ICMPv4 .pdfIP has no mechanism for error reporting or error-correcting. ICMPv4 .pdf
IP has no mechanism for error reporting or error-correcting. ICMPv4 .pdf
rishabjain5053
 
Informed Consent is a significant requirement for all provider types.pdf
Informed Consent is a significant requirement for all provider types.pdfInformed Consent is a significant requirement for all provider types.pdf
Informed Consent is a significant requirement for all provider types.pdf
rishabjain5053
 
In the MVC Architecture, why is it important to keep the model, view.pdf
In the MVC Architecture, why is it important to keep the model, view.pdfIn the MVC Architecture, why is it important to keep the model, view.pdf
In the MVC Architecture, why is it important to keep the model, view.pdf
rishabjain5053
 
in roughly 400 words please describe3 affective outcomes of diver.pdf
in roughly 400 words please describe3 affective outcomes of diver.pdfin roughly 400 words please describe3 affective outcomes of diver.pdf
in roughly 400 words please describe3 affective outcomes of diver.pdf
rishabjain5053
 
Im having issues with two homework questions. I get the gist of th.pdf
Im having issues with two homework questions. I get the gist of th.pdfIm having issues with two homework questions. I get the gist of th.pdf
Im having issues with two homework questions. I get the gist of th.pdf
rishabjain5053
 

More from rishabjain5053 (20)

write a short essay report to describe a topic of your interest rela.pdf
write a short essay report to describe a topic of your interest rela.pdfwrite a short essay report to describe a topic of your interest rela.pdf
write a short essay report to describe a topic of your interest rela.pdf
 
Write a C++ program to do the followingProject Name Computer Sho.pdf
Write a C++ program to do the followingProject Name Computer Sho.pdfWrite a C++ program to do the followingProject Name Computer Sho.pdf
Write a C++ program to do the followingProject Name Computer Sho.pdf
 
Which statement pertaining to Port Scanning is FALSEA technique use.pdf
Which statement pertaining to Port Scanning is FALSEA technique use.pdfWhich statement pertaining to Port Scanning is FALSEA technique use.pdf
Which statement pertaining to Port Scanning is FALSEA technique use.pdf
 
When did almost all animal phyla divergeSolutionAccording to .pdf
When did almost all animal phyla divergeSolutionAccording to .pdfWhen did almost all animal phyla divergeSolutionAccording to .pdf
When did almost all animal phyla divergeSolutionAccording to .pdf
 
What is the nipah virus Describe mechanism of infection How is it .pdf
What is the nipah virus Describe mechanism of infection How is it .pdfWhat is the nipah virus Describe mechanism of infection How is it .pdf
What is the nipah virus Describe mechanism of infection How is it .pdf
 
What is organizational inertia List some sources of inertia in a co.pdf
What is organizational inertia List some sources of inertia in a co.pdfWhat is organizational inertia List some sources of inertia in a co.pdf
What is organizational inertia List some sources of inertia in a co.pdf
 
Use fundamental identities to write tan t sec2t in terms of sint only.pdf
Use fundamental identities to write tan t sec2t in terms of sint only.pdfUse fundamental identities to write tan t sec2t in terms of sint only.pdf
Use fundamental identities to write tan t sec2t in terms of sint only.pdf
 
Twenty-five people responded to a questionnaire about what types of p.pdf
Twenty-five people responded to a questionnaire about what types of p.pdfTwenty-five people responded to a questionnaire about what types of p.pdf
Twenty-five people responded to a questionnaire about what types of p.pdf
 
The universe began 13 7 billion years ago, is most directly an exa.pdf
The universe began 13 7 billion years ago,  is most directly an exa.pdfThe universe began 13 7 billion years ago,  is most directly an exa.pdf
The universe began 13 7 billion years ago, is most directly an exa.pdf
 
The Stevens Company provided $57000 of services on acco.pdf
The Stevens Company provided $57000 of services on acco.pdfThe Stevens Company provided $57000 of services on acco.pdf
The Stevens Company provided $57000 of services on acco.pdf
 
The papillae on the tongue that do not contain any taste buds are the.pdf
The papillae on the tongue that do not contain any taste buds are the.pdfThe papillae on the tongue that do not contain any taste buds are the.pdf
The papillae on the tongue that do not contain any taste buds are the.pdf
 
QUESTION 13 Which of the following benefits is a component of Social .pdf
QUESTION 13 Which of the following benefits is a component of Social .pdfQUESTION 13 Which of the following benefits is a component of Social .pdf
QUESTION 13 Which of the following benefits is a component of Social .pdf
 
Padre, Inc., buys 80 percent of the outstanding common stock of Sier.pdf
Padre, Inc., buys 80 percent of the outstanding common stock of Sier.pdfPadre, Inc., buys 80 percent of the outstanding common stock of Sier.pdf
Padre, Inc., buys 80 percent of the outstanding common stock of Sier.pdf
 
Operating Systems Structure1- Explain briefly why the objectives o.pdf
Operating Systems Structure1- Explain briefly why the objectives o.pdfOperating Systems Structure1- Explain briefly why the objectives o.pdf
Operating Systems Structure1- Explain briefly why the objectives o.pdf
 
Need help with this java code. fill in lines where needed. Also, not.pdf
Need help with this java code. fill in lines where needed. Also, not.pdfNeed help with this java code. fill in lines where needed. Also, not.pdf
Need help with this java code. fill in lines where needed. Also, not.pdf
 
IP has no mechanism for error reporting or error-correcting. ICMPv4 .pdf
IP has no mechanism for error reporting or error-correcting. ICMPv4 .pdfIP has no mechanism for error reporting or error-correcting. ICMPv4 .pdf
IP has no mechanism for error reporting or error-correcting. ICMPv4 .pdf
 
Informed Consent is a significant requirement for all provider types.pdf
Informed Consent is a significant requirement for all provider types.pdfInformed Consent is a significant requirement for all provider types.pdf
Informed Consent is a significant requirement for all provider types.pdf
 
In the MVC Architecture, why is it important to keep the model, view.pdf
In the MVC Architecture, why is it important to keep the model, view.pdfIn the MVC Architecture, why is it important to keep the model, view.pdf
In the MVC Architecture, why is it important to keep the model, view.pdf
 
in roughly 400 words please describe3 affective outcomes of diver.pdf
in roughly 400 words please describe3 affective outcomes of diver.pdfin roughly 400 words please describe3 affective outcomes of diver.pdf
in roughly 400 words please describe3 affective outcomes of diver.pdf
 
Im having issues with two homework questions. I get the gist of th.pdf
Im having issues with two homework questions. I get the gist of th.pdfIm having issues with two homework questions. I get the gist of th.pdf
Im having issues with two homework questions. I get the gist of th.pdf
 

Recently uploaded

Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 

Recently uploaded (20)

Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 

Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf

  • 1. Implement the interface you wrote for Lab B (EntryWayListInterface). As a reminder, EntryWayListInterface allows the user to access to list elements only through the beginning and end of the list. Your implementation can use either an expandable array or linked nodes- it is your choice. You can decide what instance variables are needed. You must implement every method from the interface. Make sure to account for special conditions such as empty lists and singleton lists. Note: your instance data variable should be either a) an array or b) one or more nodes. It should not be an AList or LList object or an ArrayList object. Your implementation must: compile contain these implemented methods: insertHead insertTail deleteHead deleteTail display contains isEmpty isFull Also create a driver program to test your implementation. The driver program will operate from the client perspective. Your driver program should: display an empty list add five entries to the list- some at the head and some at the tail display the list remove the first entry remove the last entry display the list test to see if elements are in the list (test one element that is in the list and one that is not) remove the last three elements in the list try to remove an element from the empty list Write a second class to implement EntryWayListInterface. Instead of using an array or linked nodes, use either an AList or LList object as your instance data variable. In this way, you are using an existing data type (AList or LList) to implement a new data type (EntryWayListInterface). Inside the methods of this class, invoke methods on the AList or LList object to accomplish the task.
  • 2. /** An interface for the ADT list. Entries in a list have positions that begin with 1. * Accesses only entries that are the head or tail of the list. */ public interface EntryWayInterface { /** Adds a new entry to this list T. * @param newEntry The object to be added as a new entry. * @return True if the addition is successful, or false if not. */ public boolean insertHead(T newEntry); /** Deletes a new entry to this list T. * @param newEntry The object to be added as a new entry. * @return True if the addition is successful, or false if not. */ public boolean insertTail(T newEntry); /** Deletes the object that is at the head of list T. * @return the object that has been deleted and returns * null if no object was deleted. */ public T deleteHead(); /** Deletes the object that is at the tail of list T. * @return the object that has been deleted or else return null * if no object was deleted. */ public T deleteTail(); /** Displays the contents of the list T. */ public void display(); /** See whether this list T contains a given entry. * @param anEntry The object that is the desired entry. * @return the position of the entry that was found. * else returns false if the object is not in the list. */ public int contains(T anEntry); /** Sees whether this list is empty. * @return True if the list is empty, or false if not. */ public boolean isEmpty();
  • 3. /** Sees whether this list is full. * @return True if the list is full, or false if not. */ public boolean isFull(); }//end EntryWayInterface Solution public class LEntryWayList implements EntryWayListInterface { private Node firstNode; private Node lastNode; private int length; public LEntryWayList() { clear(); } public final void clear() { firstNode = null; lastNode = null; length = 0; } /** * Task: Places a new object at beginning of list * * @param newEntry is a valid object * @return true if insert is successful; false otherwise */ public boolean insertHead(T newEntry) { Node newNode = new Node(newEntry); if (isEmpty()) { firstNode = newNode; lastNode = newNode; } else { newNode.next = firstNode; firstNode = newNode; } length++;
  • 4. return true; } /** * Task: Places a new object at the end of the list * * @param newEntry is a valid object * @return true if insertion successful; false otherwise */ public boolean insertTail(T newEntry) { Node newNode = new Node(newEntry); if (isEmpty()) { firstNode = newNode; } else { lastNode.next = newNode; } lastNode = newNode; length++; return true; } /** * Task: delete the object at the beginning of the list * * @return the object that has been deleted */ public T deleteHead() { T result = null; if (length >= 1) { assert !isEmpty(); if (length == 1) { result = firstNode.data; firstNode = null; lastNode = null; } else { result = firstNode.data; firstNode = firstNode.next; }
  • 5. length--; } return result; } /** * Task: delete the object at the end of the list * * @return the object that has been deleted, or null if the list was empty */ public T deleteTail() { T result = null; if (length >= 1) { assert !isEmpty(); if (length == 1) { result = firstNode.data; firstNode = null; lastNode = null; } else { Node nodeBefore = getNodeAt(length - 1); Node nodeToRemove = nodeBefore.next; nodeBefore.next = null; result = nodeToRemove.data; lastNode = nodeBefore; } length--; } return result; } /** * Task: display the contents of the list on the console, in order, one per * line */ public void display() { Node currentNode = firstNode; while (currentNode != null) { System.out.println(currentNode.getData());
  • 6. currentNode = currentNode.getNext(); } } /** * Task: search the list for the given object and return its position in the * list, or -1 if it's not found * * @param anEntry is a valid object to find in the list * @return the position of the entry that was found, or -1 if it's not found */ public int contains(T anEntry) { int found = 0; Node currentNode = firstNode; while (currentNode != null) { found++; if (anEntry.equals(currentNode.getData())) { return found; } else { currentNode = currentNode.getNext(); } } return -1; } /** * Task: check to see if list is empty * * @return true if list is empty, false if list contains one or more * objects. */ public boolean isEmpty() { boolean result; if (length == 0) { assert firstNode == null; result = true; } else { assert firstNode != null;
  • 7. result = false; } return result; } /** * Task: check if list is full * * @return true if list is full, false if list has space for more objects */ public boolean isFull() { return false; // Linked lists always return false } private Node getNodeAt(int givenPosition) { assert !isEmpty() && ((1 <= givenPosition) && (givenPosition <= length)); Node currentNode = firstNode; for (int counter = 1; counter < givenPosition; counter++) { currentNode = currentNode.getNext(); } assert currentNode != null; return currentNode; } private class Node { private T data; private Node next; private Node(T dataPortion) { data = dataPortion; next = null; } private Node(T dataPortion, Node nextNode) { data = dataPortion; next = nextNode; } public T getData() { return data; }
  • 8. public void setData(T data) { this.data = data; } public Node getNext() { return next; } public void setNext(Node next) { this.next = next; } } public static void main(String []args){ LEntryWayList l = new LEntryWayList(); l.display(); } }