12.8

  1.  
    public int count()
    {
       Node current = head;
       int count = 0;
       while (current != null)
       {
          count++;
          current = current.link;
       }
       return count;
    } 
  2.  
    public void append(int item)
    {
       Node temp = new Node(item, null);
       if (head == null)
          head = temp;
       else
       {
          Node current = head;
          while (current.link != null)
             currrent = current.link;
          current.link = temp;
       }
    } 
  3.  
    public void appendList(List other)
    {
       if (head == null)
          head = other.head;
       else
       {
          Node current = head;
          while (current.link != null)
             current = current.link;
          current.link = other.head;
       }
    } 
  4.  
    public void simplify()
    {
       int temp;
       if (head != null)
          temp = head.info;
       else
          return;
       Node current = head.link;
       Node previous = head;
       while (current != null)
       {
          if (temp == current.info)
             previous.link = current.link;
          else
             previous = previous.link;
          current = current.link;
          temp = previous.info;
       }
    } 
  5.  
    public void reverse()
    {
       Node newList = null;
       Node oldList = head;
       while (oldList != null)
       {
          Node temp = new Node(oldList.info, newList);
          newList = temp;
          oldList = oldList.link;
       }
       head = newList;
    } 
    1.  
      // in Tree
      public int nodeCount()
      {
         if (root != null)
            return root.nodeCount();
         else
            return 0;
      }
      
      // in Node
      int nodeCount()
      {
         int leftCount, rightCount;
         if (lChild == null)
            leftCount = 0;
         else
            leftCount = lChild.nodeCount();
         if (rChild == null)
            rightCount = 0;
         else
            rightCount = rChild.nodeCount();
         return 1 + leftCount + rightCount;
      } 
    2.  
      // in Tree
      public int leafCount()
      {
         if (root != null)
            return root.leafCount();
         else
            return 0;
      }
      
      // in Node
      int leafCount()
      {
         if (lChild == null && rChild == null)
            return 1;
         else if (lChild == null)
            return rChild.leafCount();
         else if (rChild == null)
            return lChild.leafCount();
         else
            return lChild.leafCount() + rChild.leafCount();
      }