Create EntryWayListInerface that compiles with appropriate @comments and paramet
ID: 3608061 • Letter: C
Question
Create EntryWayListInerface that compiles with appropriate @comments and parameters with the following methods: 1. boolean insertHead (Object newEntry) 2. boolean insertTail (Object newEntry) 3. object deleteHead ( ) 4. object deleteTail ( ) 5. void display ( ) 6. int contains (object anEntry) 7. boolean isEmpty ( ) 8. boolean isFull ( ) Create EntryWayListInerface that compiles with appropriate @comments and parameters with the following methods: 1. boolean insertHead (Object newEntry) 2. boolean insertTail (Object newEntry) 3. object deleteHead ( ) 4. object deleteTail ( ) 5. void display ( ) 6. int contains (object anEntry) 7. boolean isEmpty ( ) 8. boolean isFull ( )Explanation / Answer
Am giving you the sample code snip let.
public class LinkedList
{
LinkedList()
{
first = null;
}
public void createList()
{
Data d1 = new Data(1);
Data d2 = new Data(2);
Data d3 = new Data(3);
Data d4 = new Data(4);
first = new Node(d1);
first.insertTail(d2);
first.insertTail(d3);
first.insertTail(d4);
}
public static void main(String[] args)
{
LinkedList l = new LinkedList();
createList();
}
}
public class Node
{
Node next;
Data item;
public Node(Data toStore)
{
item = toStore;
next = null;
}
public void insertTail(Data toStore)
{
if (next == null)
{
next = newNode(toStore);
next.previous =this;
}
else
{
next.insertTail(toStore);
}
}
public void insertHead(Data toStore)
{
if (previous == null)
{
previous= new Node(toStore);
previous.next = this;
}
else
{
previous.insertHead(toStore);
}
}
}
public class Data
{
private int value;
public Data(int i)
{
value = i;
}
}
New elements can be added at the head or the tail of the list.Notice that not the list head inserts new list items, but a newitem inserted with insertTail(Data) is handed down the list andappended at the end. Similarly, new elements are moved towards thelist head using the method insertHead(Data).
--------------------------------------------------------------------------------------------------------------------------- insertHead
protected void insertHead(Object o)
Insert an object at the head of the list.
Parameters:
o - the object to add
--------------------------------------------------------------------------------------------------------------------------
protected Object deleteHead()
throws NoSuchElementException
Delete the object at the head of the list.
Returns:
the object found at the head of the list.
NoSuchElementException
--------------------------------------------------------------------------------------------------------------------------- isEmpty
public boolean isEmpty ( )
This implementation returns size() == 0.
Implements method in Collection.
--------------------------------------------------------------------------------------------------------------------------- isFull
publicboolean isFull()
Tests if queue is full.
Returns:
true if queue is full; false otherwise