示例#1
0
  /**
   * Adds the given node at the end of the list.
   *
   * @param newNode the node to be added
   */
  public void addNode(ListNode newNode) {
    ListNode currentNode = this.getHeadNode();

    while (currentNode.getNextNode() != null) {
      currentNode = currentNode.getNextNode();
    }

    currentNode.setNextNode(newNode);
  }
示例#2
0
  /** This method iterates through the list and prints all values stored by the list. */
  public void printAllNodes() {
    ListNode currentNode = this.getHeadNode();

    while (currentNode != null) {
      System.out.println(currentNode.getNodeValue());
      currentNode = currentNode.getNextNode();
    }
  }