I have the below code:
public final class LinkedBag<T> implements BagInterface<T> {
private Node firstNode;
private int numberOfEntries;
public LinkedBag() {
firstNode = null;
numberOfEntries = 0;
}
// Other methods defined
public int getCurrentSize() { }
public boolean isEmpty() { }
public boolean add(T newEntry) { }
public T remove() { }
public boolean remove(T anEntry) { }
public int getFrequencyOf(T anEntry) { }
public boolean contains(T anEntry) { }
public T[] toArray() { }
public void clear() {
while(!isEmpty())
remove();
}
}
To remove all entries the above version of the clear()
method deallocates each node in the chain, thereby making it empty.
However, to remove all entries would the below version of the clear()
method deallocate all of the nodes in the chain, thereby making it empty?
public void clear() {
firstNode = null;
}