-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListElement.java
More file actions
90 lines (87 loc) · 2.38 KB
/
ListElement.java
File metadata and controls
90 lines (87 loc) · 2.38 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
/**
*This class implements the state and behaviour of a list element
*@param next a reference to the next object in the list
*@param prev a reference to the previous object in the list
*@param val an integer data value
*/
class ListElement<T>{
private ListElement<T> next,prev;
private T val;
/**
*the default ListElement constructor..
*/
public ListElement(){
//by default: next=null, prev=null,
//val=0
}
/**
*3 parameters ListElement constructor.
*@param val the T value for the new element.
*@param next the reference to the object located after the new object in the list.
*@param prev the reference to the object located before the new object in the list.
*/
public ListElement(T val, ListElement<T> next, ListElement<T> prev){
this.val=val;
this.next=next;
this.prev=prev;
}
/**
*1 parameter ListElement constructor.
@param val the T value for the new element.
*/
public ListElement(T val){
this(val,null,null); //the 3 parameter constructor
}
/**
*2 parameters ListElement constructor.
*@param val the T value for the new element.
*@param next the reference to the object stands after the new object in the list.
*/
public ListElement(T val, ListElement<T> next){
this(val,next,null); //the 3 parameter constructor
}
/**
*get method for the internal data value.
*@return the value of "this" ListElement.
*/
public T getVal(){
return this.val;
}
/**
*get method for the next ListElement reference.
*@return the next ListElement reference.
*/
public ListElement<T> getNext(){
return this.next;
}
/**
*get method for the last ListElement reference.
*@return the previous ListElement reference.
*/
public ListElement<T> getPrev(){
return this.prev;
}
/**
*set method for the next ListElement reference.
*@param next the next ListElement reference.
*/
public void setNext(ListElement<T> next){
this.next=next;
}
/**
*set method for the previous ListElement reference.
*@param the previous ListElement reference.
*/
public void setPrev(ListElement<T> prev){
this.prev=prev;
}
/**
*implementation of the toString method for this class.
*@return the String representation of the internal integer value
*held by "this" ListElement.
*/
@Override
public String toString(){
return this.getVal().toString(); //check double check
}
}