From d0972c57cc23d7a6c913594e8166770fc1b28ff6 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Wed, 11 Mar 2015 10:50:52 +0100 Subject: Added framework --- Week6/src/Node.java | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Week6/src/Node.java (limited to 'Week6/src/Node.java') 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 +{ + // the data field + private T item; + // a reference to the predecessor + private Node 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 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 getPrevious() { + return previous; + } + + /* + * determines the length of the current list + * @return the length as an integer + */ + public int length () { + int length = 1; + Node prev = previous; + while ( prev != null ) { + prev = prev.previous; + length++; + } + return length; + } + + @Override + public String toString() { + throw new UnsupportedOperationException("toString : not supported yet."); + } +} -- cgit v1.2.3