Class Set_LinkedList

  • All Implemented Interfaces:
    Iterable<Integer>, ISet

    public class Set_LinkedList
    extends Object
    implements ISet
    LinkedList of m elements add : O(1) testPresence: O(m) remove: O(m) iteration : O(m) Created by IntelliJ IDEA. User: Jean-Guillaume Fages, chameau Date: 9 fevr. 2011
    • Constructor Detail

      • Set_LinkedList

        public Set_LinkedList()
    • Method Detail

      • size

        public int size()
        Specified by:
        size in interface ISet
        Returns:
        the number of elements in the set
      • contains

        public boolean contains​(int element)
        Description copied from interface: ISet
        Test the existence of element in the set
        Specified by:
        contains in interface ISet
        Parameters:
        element - element to add
        Returns:
        true iff the set contains element
      • add

        public boolean add​(int element)
        Description copied from interface: ISet
        Add element to the set
        Specified by:
        add in interface ISet
        Parameters:
        element - element to add
        Returns:
        true iff element was not in the set and has been added
      • remove

        public boolean remove​(int element)
        Description copied from interface: ISet
        Remove the first occurrence of element from the set
        Specified by:
        remove in interface ISet
        Parameters:
        element - element to add
        Returns:
        true iff element was in the set and has been removed
      • clear

        public void clear()
        Description copied from interface: ISet
        Remove all elements from the set
        Specified by:
        clear in interface ISet
      • min

        public int min()
        Specified by:
        min in interface ISet
        Returns:
        the smallest element in the set throws an exception if the set is empty Time complexity is linear for BIPARTITESET and LINKED_LIST (constant time otherwise)
      • max

        public int max()
        Specified by:
        max in interface ISet
        Returns:
        the largest element in the set throws an exception if the set is empty Time complexity is linear for BIPARTITESET and LINKED_LIST (constant time otherwise)
      • getSetType

        public SetType getSetType()
        Specified by:
        getSetType in interface ISet
        Returns:
        the implementation type of this set
      • iterator

        public ISetIterator iterator()
        Description copied from interface: ISet
        Use the following loop to iterate over this set without autoboxing. // more readable but with autoboxing for(int value:set){ ... } // more verbose but without autoboxing ISetIterator iter = set.primitiveIterator(); while(iter.hasNext()){ int k = iter.next(); ... } Do not use this iterator to make nested loops over ISet (prefer ISet.newIterator())
        Specified by:
        iterator in interface ISet
        Specified by:
        iterator in interface Iterable<Integer>
        Returns:
        the default iterator (singleton) of this set
      • newIterator

        public ISetIterator newIterator()
        Description copied from interface: ISet
        Creates a new iterator object, for nested loops only.
        Specified by:
        newIterator in interface ISet
        Returns:
        a new iterator for this set