This repository has been archived by the owner on Mar 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
List.java
116 lines (102 loc) · 3.11 KB
/
List.java
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
package assign06;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* This interface specifies the general behavior of an ordered list of elements.
*
* @author Erin Parker
* @version March 3, 2021
*
* @param <E> - the type of elements contained in the list
*/
public interface List<E> extends Iterable<E> {
/**
* Inserts an element at the beginning of the list.
* O(1) for a singly-linked list.
*
* @param element - the element to add
*/
void insertFirst(E element);
/**
* Inserts an element at a specific position in the list.
* O(N) for a singly-linked list.
*
* @param index - the specified position
* @param element - the element to add
* @throws IndexOutOfBoundsException if index is out of range (index < 0 || index > size())
*/
void insert(int index, E element) throws IndexOutOfBoundsException;
/**
* Gets the first element in the list.
* O(1) for a singly-linked list.
*
* @return the first element in the list
* @throws NoSuchElementException if the list is empty
*/
E getFirst() throws NoSuchElementException;
/**
* Gets the element at a specific position in the list.
* O(N) for a singly-linked list.
*
* @param index - the specified position
* @return the element at the position
* @throws IndexOutOfBoundsException if index is out of range (index < 0 || index >= size())
*/
E get(int index) throws IndexOutOfBoundsException;
/**
* Deletes and returns the first element from the list.
* O(1) for a singly-linked list.
*
* @return the first element
* @throws NoSuchElementException if the list is empty
*/
E deleteFirst() throws NoSuchElementException;
/**
* Deletes and returns the element at a specific position in the list.
* O(N) for a singly-linked list.
*
* @param index - the specified position
* @return the element at the position
* @throws IndexOutOfBoundsException if index is out of range (index < 0 || index >= size())
*/
E delete(int index) throws IndexOutOfBoundsException;
/**
* Determines the index of the first occurrence of the specified element in the list,
* or -1 if this list does not contain the element.
* O(N) for a singly-linked list.
*
* @param element - the element to search for
* @return the index of the first occurrence; -1 if the element is not found
*/
int indexOf(E element);
/**
* O(1) for a singly-linked list.
*
* @return the number of elements in this list
*/
int size();
/**
* O(1) for a singly-linked list.
*
* @return true if this collection contains no elements; false, otherwise
*/
boolean isEmpty();
/**
* Removes all of the elements from this list.
* O(1) for a singly-linked list.
*/
void clear();
/**
* Generates an array containing all of the elements in this list in proper sequence
* (from first element to last element).
* O(N) for a singly-linked list.
*
* @return an array containing all of the elements in this list, in order
*/
Object[] toArray();
/**
* @return an iterator over the elements in this list in proper sequence (from first
* element to last element)
*/
public Iterator<E> iterator();
}