-
Notifications
You must be signed in to change notification settings - Fork 2
/
LinkedListNode.java
62 lines (56 loc) · 920 Bytes
/
LinkedListNode.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
public class LinkedListNode<T> {
/**
* This class creates a node
*
* Ching Ching Huang
*/
private T data;
private LinkedListNode<T> next;
/**
* Constructor to create a node
*
* @param data
*/
public LinkedListNode(T data) {
this.data = data;
next = null;
}
/**
* Set the data stored at this node.
*/
public void setData(T data) {
this.data = data;
}
/**
* Get the data stored at this node.
*/
public T getData() {
if(data == null){
return null;
}else{
return data;
}
}
/**
* Set the next pointer to passed node.
*/
public void setNext(LinkedListNode<T> node) {
this.next = node;
}
/**
* Get (pointer to) next node.
*/
public LinkedListNode<T> getNext() {
return next;
}
/**
* Returns a String representation of this node.
*/
public String toString() {
if (data == null) {
return "";
} else {
return data.toString();
}
}
}