Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This method has code checking that obj is an instance of DoublyLinkedList, and t

ID: 3808045 • Letter: T

Question

This method has code checking that obj is an instance of DoublyLinkedList, and then either return false or performs the typecast. You will need to perform a list traversal and check that the element in each Entry is equal to the element at the identical index in otherList. The algorithm you must implement in the area labeled // add code here is

here are the pseudocode for completing the following method:

set trav to the first Entry in the linked list

for i = 0 to size

set elem qual to the element at index i in otherList

if !(trav's element and elem are equal elements)

return false

End if

set trav equal to the next Entry in the list

End for

return true

________________________________________________________

public boolean equals(Object obj) {

       if (!(obj instanceof List)) {

           return false;

       } else {

           List <E> otherList = (List<E>) obj;

           if (otherList.size() != size) {

               return false;

           }

           // add your code here

}

   }

Explanation / Answer

// Implementation of given algorithm

public boolean equals(Object obj) {

public boolean equals(Object obj) {

if (!(obj instanceof List)) {

return false;

} else {

List <E> otherList = (List<E>) obj;

if (otherList.size() != size) {

return false;

}

else

{

List <E> list = (List<E>) trav;
trav = list.firstEntry() ; //set trav to the first Entry in the linked list

for(int i=0;i<size;i++)

{
List <E> otherList = (List<E>) elem;
elem=otherList.getel(i); //set elem qual to the element at index i in otherList

if !(trav.getElem() == elem ) {

return false ;

}

trav = list.nextEntry(); // set trav equal to the next Entry in the list

}

return true;

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote