Package it.unimi.di.prog2.s19
Class OrderedIntList
java.lang.Object
it.unimi.di.prog2.s19.OrderedIntList
Ordered list of integers without duplicates.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
Indicates if the list is empty.private OrderedIntList
Two sublists, containing values respectively smaller and greater thanvalue
.private OrderedIntList
Two sublists, containing values respectively smaller and greater thanvalue
.private int
The value stored in this node of the list. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
hashCode()
boolean
isEmpty()
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
size()
Returns the number of elements in the list.Iterator that lists the elements of the list in ascending order.
-
Field Details
-
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
Iterator that lists the elements of the list in ascending order.- Returns:
- the iterator.
-
bigToSmall
Iterator that lists the elements of the list in descending order.- Returns:
- the iterator.
-
equals
-
hashCode
public int hashCode()
-