-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectNode.java
More file actions
63 lines (46 loc) · 1.33 KB
/
ObjectNode.java
File metadata and controls
63 lines (46 loc) · 1.33 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
// ObjectNode.java
// Similar to IntNode.java except ObjectNode.java uses
// more general Object data in place of int data
// March 2019
public class ObjectNode {
private Object data;
private ObjectNode next;
public ObjectNode() {} // default constructor
public ObjectNode(Object data, ObjectNode next) {
this.data = data;
this.next = next;
}
// accessor methods
public Object getData() {
return data;
}
public ObjectNode getNext() {
return next;
}
public void setData(Object value) {
data = value;
}
public void setNext(ObjectNode ptr) {
next = ptr;
}
public boolean equals(Object anotherObject) {
// returns true iff both fields of
// the corresponding nodes are ==
if (anotherObject instanceof ObjectNode) {
ObjectNode temp = (ObjectNode) anotherObject;
if (data == temp.getData() &&
next == temp.getNext())
return true;
}
return false;
}
public String toString() {
return data.toString();
}
public static void main(String[] args) {
// tests the ObjectNode class by building a short list of
// various data items
ObjectNode start = null;
ObjectNode ptr;
} // main
} // ObjectNode