generated from ZipCodeCore/OldTexasCode2
-
Notifications
You must be signed in to change notification settings - Fork 11
/
ListNode.java
75 lines (63 loc) · 1.55 KB
/
ListNode.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
/**
* A class that represents a node to be used in a linked list.
* These nodes are singly linked.
*
* @author Mike Scott
* @version July 27, 2005
*/
public class ListNode
{
// instance variables
// the data to store in this node
private Object myData;
// the link to the next node (presumably in a list)
private ListNode myNext;
/**
* default constructor
* pre: none<br>
* post: getData() = null, getNext() = null
*/
public ListNode()
{ this(null, null);
}
/**
* create a ListNode that holds the specified data and refers to the specified next element
* pre: none<br>
* post: getData() = item, getNext() = next
* @param item the data this ListNode should hold
* @param next the next node in the list
*/
public ListNode(Object data, ListNode next)
{ myData = data;
myNext = next;
}
/**
* return the data in this node
* pre: none<br>
* @return the data this ListNode holds
*/
public Object getData()
{ return myData; }
/**
* return the ListNode this ListNode refers to
* pre: none<br>
* @return the ListNode this ListNode refers to (normally the next one in a list)
*/
public ListNode getNext()
{ return myNext; }
/**
* set the data in this node
* The old data is over written.<br>
* pre: none<br>
* @param data the new data for this ListNode to hold
*/
public void setData(Object data)
{ myData = data; }
/**
* set the next node this ListNode refers to
* pre: none<br>
* @param next the next node this ListNode should refer to
*/
public void setNext(ListNode next)
{ myNext = next; }
}