-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.java
More file actions
116 lines (103 loc) · 2.81 KB
/
Copy pathNode.java
File metadata and controls
116 lines (103 loc) · 2.81 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
* A node is an abstract data structure.
*
* @author Sachith Ranaweera
* @version 1.0 2016-10-21
*/
public class Node
{
/* instance field */
private int data;
private Node nextNode;
/* constructors */
/**
* Contructs an empty node which does not point to another.
*/
public Node()
{
data = 0;
nextNode = null;
} // end of constructore Node()
/**
* Constructs a node with the specified data and link to a
* node which follows this node.
*
* @param data the data to be store in this node
* @param the node wich follows this node
*/
public Node(int data, Node nextNode)
{
this.data = data;
this.nextNode = nextNode;
} // end of method Node(String data, Node next)
/* accessors */
/**
* Compares this node to the specified node.
*
* @param otherObject the object to which this node is compared
* @return true if node is the same as otherObject
* , otherwise false.
*/
public boolean equals(Object otherObject)
{
if (otherObject == null) return false;
if (getClass() != otherObject.getClass()) return false;
Node other = (Node) otherObject;
// is this data not equal to the other data?
if (data != other.data)
{
return false;
} //end of if (data != other.data)
return true;
} // end of method equals(Object otherObject)
/**
* Returns the data stored in this node.
*
* @return the data stored in this node.
*/
public int getData()
{
return data;
} // end of method getData()
/**
* Returns the node which follows this node.
*
* @return the node which follows this node.
*/
public Node getNext()
{
return nextNode;
} // end of getNext()
/* mutators */
/**
* Sets the data to be stored in this node.
*
* @param data the datat to be stored in this node
*/
public void setData(int data)
{
this.data = data;
} // end of setData(String data)
/**
* Sets the node which follows this node.
*
* @param next the node wich is to follow this node
*/
public void setNext(Node nextNode)
{
this.nextNode = nextNode;
} // end of setNext(Node next)
/**
* Returns a string representation of this node.
*
* @return a string reprecentation of this node.
*/
public String toString()
{
return
getClass().getName()
+ "[Data: " + data
+ ", next node: " + nextNode
+ "]";
} // end of toString()
} // end of class Node