JavaAlgorithms
Elementary and no so elementary Java algorithms
listAlgorithms/ListNode.java
Go to the documentation of this file.
00001 
00009 package listAlgorithms;
00010 
00011 import java.util.Iterator;
00012 
00020 public class ListNode<T extends Comparable<T>> implements Iterable<ListNode<T>> {
00021     private T mValue;
00022     private ListNode<T> mNext;
00023 
00024     @SuppressWarnings("javadoc")
00025     public ListNode(T value) {
00026         this.mValue = value;
00027         this.mNext = null;
00028     }
00029 
00030     @SuppressWarnings("javadoc")
00031     public T getValue() {
00032         return mValue;
00033     }
00034 
00035     @SuppressWarnings("javadoc")
00036     public void setValue(T value) {
00037         this.mValue = value;
00038     }
00039 
00040     @SuppressWarnings("javadoc")
00041     public ListNode<T> getNext() {
00042         return mNext;
00043     }
00044 
00045     @SuppressWarnings("javadoc")
00046     public void setNext(ListNode<T> next) {
00047         this.mNext = next;
00048     }
00049 
00050     @SuppressWarnings("javadoc")
00051     public void printList() {
00052         String s = this.getValue().toString();
00053         System.out.print("[" + s + "]");
00054         if (this.getNext() != null) {
00055             System.out.print("->");
00056             this.getNext().printList();
00057         } else {
00058             System.out.println();
00059         }
00060     }
00061 
00062     @Override
00063     public Iterator<ListNode<T>> iterator() {
00064         Iterator<ListNode<T>> iter = new ListNodeIterator<T>(this);
00065         return iter;
00066     }
00067 
00068 }
 All Classes Namespaces Files Functions Variables