-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathLinkedList.java
171 lines (155 loc) · 4.12 KB
/
LinkedList.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
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
package com.linkedlist;
/**
* In computer science, a linked list is a linear collection of data elements,
* called nodes, each pointing to the next node by means of a pointer. It is a
* data structure consisting of a group of nodes which together represent a
* sequence. Under the simplest form, each node is composed of data and a
* reference (in other words, a link) to the next node in the sequence. This
* structure allows for efficient insertion or removal of elements from any
* position in the sequence during iteration. More complex variants add
* additional links, allowing efficient insertion or removal from arbitrary
* element references.
*
* {@link https://en.wikipedia.org/wiki/Linked_list}
*
* @author STEPHANE MIGUEL KAKANAKOU (Skakanakou@gmail.com)
*
*/
public interface LinkedList<Item> extends Iterable<Item> {
/**
* returns number of data elements in list.
*
* @return the size of the linked list
*/
int size();
/**
* Returns true if this linked list contains no items.
*
* @return true if this linked list contains no items
*/
boolean empty();
/**
* Returns the value of the nth item (starting at 0 for first).
*
* @param index
* @return The value of the nth item (starting at 0 for first).
*
* @exception IllegalArgumentException
* when index < 0 or index >=size
* @exception NullPointerException
* when the list is empty
*/
Item value_at(int index);
/**
* Adds an item to the front of the list.
*
* @param item
* Item to add to the front of this Linked list
*
* @exception IllegalArgumentException
* when item is null
*
*/
void push_front(Item item);
/**
* Remove front item and return its value
*
* @return The front item
*
* @exception NullPointerException
* when the list is empty
*
*/
Item pop_front();
/**
* adds an item at the end of the linked list
*
* @param item
* Item to add to the end of this Linked list
*
* @exception IllegalArgumentException
* when item is null
*
*/
void push_back(Item item);
/**
* removes end item and returns its value.
*
* @return the end item
*
* @exception NullPointerException
* when the list is empty
*
*/
Item pop_back();
/**
* Get value of front item
*
* @return the front item
*
* @exception NullPointerException
* when the list is empty
*
*/
Item front();
/**
* Get value of end item
*
* @return the end item
*
* @exception NullPointerException
* when the list is empty
*
*/
Item back();
/**
* insert the given item at index, so current item at that index is pointed
* to by new item at index
*
* @param index
* The index to insert into.
* @param item
* The item to insert at index.
*
* @exception IllegalArgumentException
* when index < 0 or index >size or when item is null
*
*/
void insert(int index, Item item);
/**
* removes item at given index
*
* @param index
*
* @exception IllegalArgumentException
* when index < 0 or index >= size
*
*/
void erase(int index);
/**
* returns the value of the node at backIndex position from the end of the
* list
*
* @param n
* @return
*
* @exception IllegalArgumentException
* when index < 0 or index > size
*
*/
Item value_n_from_end(int backIndex);
/**
* reverses the list
*/
void reverse();
/**
* removes the first item in the list with this value
*
* @param item
*
* @exception IllegalArgumentException
* when item is null
*
*/
void remove_value(Item item);
}