Implement interface with linked lists

0

Good evening guys,

I needed some help here. I'm starting to learn the implementation of linked lists in java, but I can not understand or find a solution to this.

I have this interface:

public interface ISet<E> extends Iterable<E> {
/**
* Inserts another element in the set.
* @param x The element to be inserted
* @requires x!=null
*/
public void insert (E x);

/**
* Removes a given element from the set.
* @param x The element to be removed
* @requires x!=null
*/

public void remove (E x);

/**
* Returns an element of the set.
* @param i
* @return
* @requires 0 <= i < size()
*/
public E get(int i);

/**
* Returns true if the element is in the set and false otherwise.
* @param x The element
* @return if the element is in the set
* @requires x!=null
*/
public boolean isIn(E x);

/**
* Returns true if the set is empty and false otherwise.
* @return if the set is empty
*/
public boolean isEmpty();
/**
* Returns the cardinality of the set
* @return the number of elements in the set
*/
public int size();

/**
* Returns true if other is s subset of this and false otherwise.
* @param other The other set
* @return if the set is subset of this
*/
public boolean subSet(ISet<? extends E> other);

/**
* Returns a generator that produces all elements of the set,
* exactly once in arbitrary order
* @return an iterator of the elements in the set
* @requires this not be modified while the generator is used
*/
public Iterator<E> iterator();
}

And I need to build an implementation for this interface using linked lists. Can someone help me?

I know I need to start like this:

public class Set<E extends Iterable<E>> implements ISet<E>{
    private Node<E> head;
    private int size;

    public Set() {
        head=null;
        size=0;
    }
class Node<E extends Comparable<E>>{
        private E element;
        Node<E> next;

        public Node(E e) {
            element = e;
            next = null;
        }

        @Override
        public String toString() {
            return element.toString();
        }
    }
    
asked by anonymous 30.01.2018 / 21:29

0 answers