forked from rampatra/Algorithms-and-Data-Structures-in-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkedList.java
135 lines (117 loc) · 2.82 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
package com.rampatra.base;
/**
* A generic interface for LinkedList.
*
* @author rampatra
* @since 6/16/15
*/
public interface LinkedList<E extends Comparable<E>> {
/**
* Appends the specified element to the end of this list.
*
* @param item
* @return {@code true} (as specified by {@link java.util.Collection#add})
*/
boolean add(E item);
/**
* Inserts the specified element at the specified position in this list.
*
* @param index
* @param item
* @return
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
boolean add(int index, E item);
/**
* Inserts the specified element at the beginning of this list.
*
* @param item
*/
void addFirst(E item);
/**
* Appends the specified element to the end of this list.
*
* @param item
*/
void addLast(E item);
/**
* Removes all of the elements from this list.
*/
void clear();
/**
* Returns a shallow copy of this LinkedList.
*
* @return
*/
LinkedList<E> clone();
/**
* Returns true if this list contains the specified element.
*
* @param item
* @return
*/
boolean contains(E item);
/**
* Returns the element at the specified position in this list.
*
* @param index
* @return
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
E get(int index);
/**
* Returns the first element in this list.
*
* @return
* @throws java.util.NoSuchElementException if this list is empty
*/
E getFirst();
/**
* Returns the last element in this list.
*
* @return
* @throws java.util.NoSuchElementException if this list is empty
*/
E getLast();
/**
* Prints the contents of this list.
*/
void printList();
/**
* Retrieves and removes the head (first element) of this list.
*
* @return
* @throws java.util.NoSuchElementException if this list is empty
*/
E remove();
/**
* Removes the element at the specified position in this list.
*
* @param index
* @return
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
E remove(int index);
/**
* Removes the first occurrence of the specified element from this list, if it is present.
*
* @param item
* @return {@code true} if this list contained the specified element
*/
boolean removeItem(E item);
/**
* Replaces the element at the specified position in this list with the specified element.
*
* @param index
* @param item
* @return
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
E set(int index, E item);
/**
* Returns the number of elements in this list.
*
* @return
*/
int size();
}