Question: The BilinkedList 2 8 0 classes in lib 2 8 0 - asn 1 are incomplete. There are missing method bodies in each class. Each
The BilinkedList classes in libasn are incomplete. There are missing method bodies in each class. Each missing method body is tagged with a TODO comment. Write code to implement each of these unfinished method. Implementation Notes the javadoc headers for each method explain what each method is supposed to do Many of the methods you must implement override methods of the LinkedList superclass. Add your code right into the existing files within the libasn module.When implementing the methods, consider carefully any special cases that might cause need to update
the cursor position, or ensure that it remains in a valid state.You are not permitted to modify any existing code in the java files given. You may only fill in the missing method bodies.
This is the Bilinkedlist class starter file please add all the missing methods and answer the question above
package liblist;
import libbase.BilinearIterator;
import libbase.CursorPosition;
import libbase.Pair;
import libexception.;
This list class incorporates the functions of an iterated
dictionary such as has, obtain, search, goFirst, goForth,
deleteItem, etc. It also has the capabilities to iterate backwards
in the list, goLast and goBack.
public class BilinkedList extends LinkedList implements BilinearIterator
Note that because firstRemainder and remainder should not cut links of the original list,
the previous node reference of firstNode is not always correct.
Also, the instance variable prev is generally kept up to date, but may not always be correct.
Use previousNode instead!
Construct an empty list.
Analysis: Time O
public BilinkedList
super;
Create a BilinkedNode this Bilinked list. This routine should be
overridden for classes that extend this class that need a specialized node.
@param item element to store in the new node
@return a new node containing item
protected BilinkedNode createNewNodeI item
TODO
return null; This line is present only to prevent a compile error. You should remove it before
completing this method.
Insert element at the beginning of the list
@param x item to be inserted at the beginning of the list
public void insertFirstI x
TODO
Insert element at the beginning of the list
@param x item to be inserted at the beginning of the list
public void insertI x
this.insertFirstx;
Insert an item before the current position.
@param x The item to be inserted.
public void insertBeforeI x throws InvalidStateException
if this.before throw new InvalidStateExceptionCannot insertBefore when the cursor is already before the first element.";
If the item goes at the beginning or the end, handle those special cases.
if this.head position
insertFirstx; special case inserting before first element
else if this.after
insertLastx; special case inserting at the end
else
Otherwise, insert the node between the current position and the previous position.
BilinkedNode newNode createNewNodex;
newNode.setNextNodeposition;
newNode.setPreviousNodeBilinkedNodethisprevPosition;
prevPosition.setNextNodenewNode;
BilinkedNodethispositionsetPreviousNodenewNode;
since position didn't change, but we changed it's predecessor, prevPosition needs to be updated to be the new previous node.
prevPosition newNode;
Insert x before the current position and make it current item.
Analysis: Time O
@param x item to be inserted before the current position
public void insertPriorGoI x
this.insertBeforex;
this.goBack;
Insert x after the current item.
Analysis: Time O
@param x item to be inserted after the current position
public void insertNextI x
if isEmpty before
insertFirstx;
else if thispositionlastNode
insertLastx;
else if after if after then have to deal with previous node
insertLastx;
this.position this.prevPosition.nextNode;
else in the list, so create a node and set the pointers to the new node
BilinkedNode temp createNewNodex;
temp.setNextNodethisposition.nextNode;
temp.setPreviousNodeBilinkedNodethisposition;
BilinkedNode this.position.nextNodesetPreviousNodetemp;
this.position.setNextNodetemp;
Insert a new element at the end of the list
@param x item to be inserted at the end of the list
public void insertLastI x
TODO
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
