logo Practice-It logo

count

Related Links:
Author: Marty Stepp (on 2012/02/29)

Write a method count that accepts an element value as a parameter and returns the number of occurrences of that value in the list. For example, suppose a variable named list stores the following sequence of elements:

[one, two, three, two, four, two, five, two, two, six]

A call of list.count("two") should return 5 because there are five occurrences of that value in the list. If the list does not contain the value at all, return 0.

The example shown is a list of strings, but this is a generic linked list class that can store any type of objects. Assume that you are adding this method to the LinkedList<E> class as defined below:

public class LinkedList<E> {
    private ListNode front;   // null for an empty list
    ...
}
Type your solution here:


This is a partial class problem. Submit code that will become part of an existing Java class as described. You do not need to write the complete class, just the portion described in the problem.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.