Exemplo n.º 1
0
 /**
  * Returns a string representation of the contents of the linked list, from the front to the back.
  *
  * @return a string representation of the linked list, from front to back
  */
 public String toString() {
   if (isEmpty()) {
     return "";
   } else if (getHead() == getTail()) {
     // one element
     return getHead().getElement().toString();
   } else {
     StringBuilder newString = new StringBuilder();
     DLNode<T> placeHolder = getHead();
     // loop through and build string node by node
     while (placeHolder.getNext() != null) {
       newString.append(placeHolder.getElement().toString());
       placeHolder = placeHolder.getNext();
     }
     newString.append(placeHolder.getElement().toString());
     return newString.toString();
   }
 }
Exemplo n.º 2
0
 /**
  * {@inheritDoc}
  *
  * @return returns next element from list
  */
 public DLNode<T> next() {
   if (iterNode == null) {
     // end of list so no more elements
     throw new NoSuchElementException();
   } else {
     // increment iterNode and return previous value
     DLNode<T> temp = iterNode;
     iterNode = iterNode.getNext();
     return temp;
   }
 }