-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.java
More file actions
86 lines (60 loc) · 1.32 KB
/
Copy pathNode.java
File metadata and controls
86 lines (60 loc) · 1.32 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
package edu.cofc.cs.csci230;
/**
* A node with only one pointer (i.e. to the next
* node in front of it) to be used in a singly
* linked list linear data structure
*
* @author CSCI 230: Data Structures and Algorithms Fall 2016
*
* @param <AnyType>
*/
public class Node<AnyType extends Comparable> {
// instance variables
private AnyType data;
private Node<AnyType> nextNode;
/**
*
* @param data
*/
public Node( AnyType data ) {
setData( data );
} // end constructor
/**
*
* @param data
*/
public void setData( AnyType data ) {
this.data = data;
} // end setData() method
/**
*
* @return
*/
public AnyType getData() {
return data;
} // end getData() method
/**
*
* @param nextNode
*/
public void setNextNode( Node<AnyType> nextNode ) {
this.nextNode = nextNode;
} // end setNextNode() method
/**
*
* @return
*/
public Node<AnyType> getNextNode() {
return nextNode;
} // end getNextNode() method
/**
*
*/
public String toString() {
if ( getNextNode() != null ) {
return String.format("%s -> %s\n", getData().toString(), getNextNode().getData().toString() );
} else {
return String.format( "%s -> NULL\n", getData().toString() );
}
} // end toString() method
} // end Node class definition