Question: import java.util.*; public class FreqAndRankContainer { String items1; ArrayList a = new ArrayList (); String[] items; int size; // constructor public FreqAndRankContainer() { } //
import java.util.*;
public class FreqAndRankContainer {
String items1;
ArrayList
String[] items;
int size;
// constructor
public FreqAndRankContainer() {
}
// add a new copy of "item" to the container
void add(String item) {
a.add(item);
}
// Removes one copy of "item" from the container.
// Return true iff the item was removed. Returns false
// if the item was not in the container to begin with.
boolean remove(String item) {
for(int i = 0; i < size; i++) {
if(items[i].equals(item)) {
items[i] = items[size - 1];
items[size - 1] = null;
size--;
return true;
}
}
return false;
}
// Returns the total number of items in the container.
int getSize() {
return a.size();
}
// Returns the number copies of "item" in the container.
int getFrequency(String item) {
int count = 0;
for(int i = 0; i < size; i++) {
if(item.equals(items[i])) {
count ++;
}
}
return count;
}
// Returns the item that has the most occurrences. If a tie,
// returns the one alphabetically first. If none, return null.
String getMostFrequentItem() {
return null;
}
// Returns the ith value in the container, where the values
String getIthRank(int i) {
HashSet
set.add(items1);
Iterator
while(itr.hasNext()){
System.out.println(itr.next());
}
return null;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
