-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndexedUnsortedList.java
More file actions
186 lines (165 loc) · 5.93 KB
/
IndexedUnsortedList.java
File metadata and controls
186 lines (165 loc) · 5.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import java.util.*;
/**
* Interface for an Iterable, Indexed, Unsorted List ADT.
* Iterators and ListIterators provided by the list are required
* to be "fail-fast" and throw ConcurrentModificationException if
* the iterator detects any change to the list from another source.
* Note: "Unsorted" only means that it is not inherently maintained
* in a sorted order. It may or may not be sorted.
*
* @author CS 221
*
* @param <T> - class of objects stored in the list
*/
public interface IndexedUnsortedList<T> extends Iterable<T>
{
/**
* Adds the specified element to the front of this list.
*
* @param element the element to be added to the front of this list
*/
public void addToFront(T element);
/**
* Adds the specified element to the rear of this list.
*
* @param element the element to be added to the rear of this list
*/
public void addToRear(T element);
/**
* Adds the specified element to the rear of this list.
*
* @param element the element to be added to the rear of the list
*/
public void add(T element);
/**
* Adds the specified element after the specified target.
*
* @param element the element to be added after the target
* @param target the target is the item that the element will be added after
* @throws NoSuchElementException if target element is not in this list
*/
public void addAfter(T element, T target);
/**
* Inserts the specified element at the specified index.
*
* @param index the index into the array to which the element is to be inserted.
* @param element the element to be inserted into the array
* @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index > size)
*/
public void add(int index, T element);
/**
* Removes and returns the first element from this list.
*
* @return the first element from this list
* @throws NoSuchElementException if list contains no elements
*/
public T removeFirst();
/**
* Removes and returns the last element from this list.
*
* @return the last element from this list
* @throws NoSuchElementException if list contains no elements
*/
public T removeLast();
/**
* Removes and returns the first element from the list matching the specified element.
*
* @param element the element to be removed from the list
* @return removed element
* @throws NoSuchElementException if element is not in this list
*/
public T remove(T element);
/**
* Removes and returns the element at the specified index.
*
* @param index the index of the element to be retrieved
* @return the element at the given index
* @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size)
*/
public T remove(int index);
/**
* Replace the element at the specified index with the given element.
*
* @param index the index of the element to replace
* @param element the replacement element to be set into the list
* @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size)
*/
public void set(int index, T element);
/**
* Returns a reference to the element at the specified index.
*
* @param index the index to which the reference is to be retrieved from
* @return the element at the specified index
* @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size)
*/
public T get(int index);
/**
* Returns the index of the first element from the list matching the specified element.
*
* @param element the element for the index is to be retrieved
* @return the integer index for this element or -1 if element is not in the list
*/
public int indexOf(T element);
/**
* Returns a reference to the first element in this list.
*
* @return a reference to the first element in this list
* @throws NoSuchElementException if list contains no elements
*/
public T first();
/**
* Returns a reference to the last element in this list.
*
* @return a reference to the last element in this list
* @throws NoSuchElementException if list contains no elements
*/
public T last();
/**
* Returns true if this list contains the specified target element.
*
* @param target the target that is being sought in the list
* @return true if the list contains this element, else false
*/
public boolean contains(T target);
/**
* Returns true if this list contains no elements.
*
* @return true if this list contains no elements
*/
public boolean isEmpty();
/**
* Returns the number of elements in this list.
*
* @return the integer representation of number of elements in this list
*/
public int size();
/**
* Returns a string representation of this list.
*
* @return a string representation of this list
*/
public String toString();
/**
* Returns an Iterator for the elements in this list.
*
* @return an Iterator over the elements in this list
*/
public Iterator<T> iterator();
/**
* Returns a ListIterator for the elements in this list.
*
* @return a ListIterator over the elements in this list
*
* @throws UnsupportedOperationException if not implemented
*/
public ListIterator<T> listIterator();
/**
* Returns a ListIterator for the elements in this list, with
* the iterator positioned before the specified index.
*
* @return a ListIterator over the elements in this list
*
* @throws UnsupportedOperationException if not implemented
*/
public ListIterator<T> listIterator(int startingIndex);
}