forked from srafi1-stuycs/deque
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DLLNode.java
53 lines (39 loc) · 1.32 KB
/
DLLNode.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
/*****************************************************
* class DLLNode
* Implements a node, for use in lists and other container classes.
*****************************************************/
public class DLLNode<T>
{
private T _cargo; //cargo may only be of type T
private DLLNode<T> _nextNode, _prevNode; //pointers to next, prev DLLNodes
// constructor -- initializes instance vars
public DLLNode( T value, DLLNode<T> prev, DLLNode<T> next ) {
_cargo = value;
_nextNode = next;
_prevNode = prev;
}
//--------------v ACCESSORS v--------------
public T getValue() { return _cargo; }
public DLLNode<T> getNext() { return _nextNode; }
public DLLNode<T> getPrev() { return _prevNode; }
//--------------^ ACCESSORS ^--------------
//--------------v MUTATORS v--------------
public T setValue( T newCargo ) {
T foo = getValue();
_cargo = newCargo;
return foo;
}
public DLLNode<T> setNext( DLLNode<T> newNext ) {
DLLNode<T> foo = getNext();
_nextNode = newNext;
return foo;
}
public DLLNode<T> setPrev( DLLNode<T> newPrev ) {
DLLNode<T> foo = getPrev();
_prevNode = newPrev;
return foo;
}
//--------------^ MUTATORS ^--------------
// override inherited toString
public String toString() { return _cargo.toString(); }
}//end class DLLNode