Class OrderedIntList

java.lang.Object
it.unimi.di.prog2.s19.OrderedIntList

public class OrderedIntList extends Object
Ordered list of integers without duplicates.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private boolean
    Indicates if the list is empty.
    Two sublists, containing values respectively smaller and greater than value.
    Two sublists, containing values respectively smaller and greater than value.
    private int
    The value stored in this node of the list.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an empty list.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(int value)
    Adds an element to the list.
    Iterator that lists the elements of the list in descending order.
    boolean
    contains(int value)
    Consente di determinare se un valore appartiene alla lista.
    boolean
     
    int
     
    boolean
    Determines if the list is empty.
    int
    max()
    Returns the maximum value in the list.
    int
    min()
    Returns the minimum value in the list.
    boolean
    remove(int value)
    Removes an element from the list.
    int
    Returns the number of elements in the list.
    Iterator that lists the elements of the list in ascending order.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • isEmpty

      private boolean isEmpty
      Indicates if the list is empty.
    • value

      private int value
      The value stored in this node of the list.
    • left

      private OrderedIntList left
      Two sublists, containing values respectively smaller and greater than value.
  • Constructor Details

    • OrderedIntList

      public OrderedIntList()
      Constructs an empty list.
  • Method Details

    • size

      public int size()
      Returns the number of elements in the list.
      Returns:
      the number of elements in the list, 0 if it is empty.
    • isEmpty

      public boolean isEmpty()
      Determines if the list is empty.
      Returns:
      true if the list is empty, false otherwise.
    • contains

      public boolean contains(int value)
      Consente di determinare se un valore appartiene alla lista.
      Parameters:
      value - il valore da cercare.
      Returns:
      se appartiene alla lista.
    • add

      public void add(int value)
      Adds an element to the list.
      Parameters:
      value - the element to add.
      Throws:
      IllegalArgumentException - if the element is already present.
    • min

      public int min()
      Returns the minimum value in the list.
      Returns:
      the minimum value in the list.
      Throws:
      NoSuchElementException - if the list is empty.
    • max

      public int max()
      Returns the maximum value in the list.
      Returns:
      the maximum value in the list.
      Throws:
      NoSuchElementException - if the list is empty.
    • remove

      public boolean remove(int value)
      Removes an element from the list.
      Parameters:
      value - the element to remove.
      Returns:
      true if the element was removed, false otherwise.
    • smallToBig

      public Iterator<Integer> smallToBig()
      Iterator that lists the elements of the list in ascending order.
      Returns:
      the iterator.
    • bigToSmall

      public Iterator<Integer> bigToSmall()
      Iterator that lists the elements of the list in descending order.
      Returns:
      the iterator.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object