diff options
author | Camil Staps | 2015-03-11 10:50:52 +0100 |
---|---|---|
committer | Camil Staps | 2015-03-11 10:50:52 +0100 |
commit | d0972c57cc23d7a6c913594e8166770fc1b28ff6 (patch) | |
tree | b64f573920d6796ffc0612476ad25dbe4135b53f /Week6/src/Node.java | |
parent | Week 6 framework (diff) |
Added framework
Diffstat (limited to 'Week6/src/Node.java')
-rw-r--r-- | Week6/src/Node.java | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/Week6/src/Node.java b/Week6/src/Node.java new file mode 100644 index 0000000..2a33cc4 --- /dev/null +++ b/Week6/src/Node.java @@ -0,0 +1,58 @@ +/**
+ * For maintaining lists of T-elements enabling
+ * a structure suited for backwards traversal
+ * @author Pieter Koopman, Sjaak Smetsers
+ * @version 1.2
+ * @date 28-02-2015
+ */
+public class Node<T>
+{
+ // the data field
+ private T item;
+ // a reference to the predecessor
+ private Node<T> previous;
+
+ /* A constructor that initializes each node
+ * with the specified values
+ * @param from the node preceding the current node
+ * @param item the initial data item
+ */
+ public Node (Node<T> from, T item) {
+ this.previous = from;
+ this.item = item;
+ }
+
+ /* a getter for the item
+ * @return item
+ */
+ public T getItem() {
+ return item;
+ }
+
+ /*
+ * a getter for the predecessor
+ * @return previous
+ */
+ public Node<T> getPrevious() {
+ return previous;
+ }
+
+ /*
+ * determines the length of the current list
+ * @return the length as an integer
+ */
+ public int length () {
+ int length = 1;
+ Node<T> prev = previous;
+ while ( prev != null ) {
+ prev = prev.previous;
+ length++;
+ }
+ return length;
+ }
+
+ @Override
+ public String toString() {
+ throw new UnsupportedOperationException("toString : not supported yet.");
+ }
+}
|