Question: 1. Write a Java program that extends the LinkedList class to ExtLinkedList containing the following methods. For time-complexity, assume the size of the list to

1. Write a Java program that extends the LinkedList class to ExtLinkedList containing the following methods. For time-complexity, assume the size of the list to be n elements. (20 points)

(a) public int countOccurences(E element) that returns the number of occurrences of element in the LinkedList if the element is found otherwise returns -1. Also, handle the condition when the list is empty. The underlying algorithm of your code should run in O(n) time.

(b) public boolean pairPresence(E element1, E element2) that checks if element1, and element2 are present in the linked list as a consecutive pair and if so returns true, if not, returns false. If there is more than one consecutive pair, you will return the first pair starting from the head of the list. Also, the code should return false when the list is empty or if it has only one element. You can use .equals() method for checking equality of elements. The underlying algorithm of your code should run in O(n) time.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!