So, I have to implement a linked-list to create a collection. I have to create the add, remove, union, equals, contains, isEmpty, size, and iterator method. I also have to implement an interface. Here is my code so far. I need help getting started. I just did this same assignment with an Array-List, but now with an Linked-List. Should the code be different?
I have to use the fields that I have, my teacher gave them to me. contents and count.
import java.util.Iterator; public class LinkedSet<T> implements SetADT<T>{ private LinearNode<T> contents; //private T[] contents; private int count; // Constructs an empty set public LinkedSet(){ this.count = 0; this.contents = null; } @Override public void add(T element) { //TODO: put in branch to handle empty and not empty differently LinearNode<T> node = new LinearNode<T>(); node.setElement(element); this.count++; //TODO: by def of set, check to see if element already contained } @Override public T removeRandom() throws Exception { // TODO Auto-generated method stub return null; } @Override public void remove(T element) { // TODO Auto-generated method stub } @Override public SetADT<T> union(SetADT<T> set) { // TODO Auto-generated method stub return null; } @Override public boolean contains(T element) { for (int i = 0; i < count; i++) { if (contents.equals(element)) { return true; } } return false; } @Override public boolean equals(SetADT<T> set) { Iterator<T> t = set.iterator(); while (t.hasNext()) { if (!this.contains(t.next())) return false; } return true; } @Override public boolean isEmpty() { // TODO Auto-generated method stub return false; } @Override public int size() { return count; } @Override public Iterator<T> iterator() { // TODO Auto-generated method stub return null; } }