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

Part C (10 marks) Consider an ADT list of integers as described in the lectures.

ID: 3903539 • Letter: P

Question

Part C (10 marks) Consider an ADT list of integers as described in the lectures.e code for determines how many times a giwen integer eccurs in the misr uses operations must be independent of the list's implementation (i.e,ony specified by the ListInterface ADT. method list. The code for your me operations as For your reference, recall the Listinterface ADT operations are: . isEmpty . getLength . insert removeAll . retrieve Assume that list indices start at 0. Some marks will be given for the quality of your answer // Deternines how many tines int x accurs in alist. // Input: alist is a list af integers, a target int x. // Output: returns the count of occurrences of int x in alist // Returns 0 if alist is empty. public static int countInList(listInterface alist, int x) ( int 1

Explanation / Answer

public static int countInList(ListInterface aList, int x)
{
int count = 0;
for(int i = 0; i < aList.getLength(); i++)
{
if(aList.retrieve(i) == x)
count++;
}
return count;
}