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
(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
Get step-by-step solutions from verified subject matter experts
