12.1

  1. B: ref.link
    C: ref.link.link
    D: ref.link.link.info
  2.  
    public void printList()
    {
       Node temp = head;
       if (temp == null)
          System.out.println("The list is empty.");
       while (temp != null)
       {
          System.out.println(temp.info);
          temp = temp.link;
       }
    } 
  3.  
    public int sum ()
    {
       int result = 0;
       Node temp = head;
       while (temp != null)
       {
          result += temp.info;
          temp = temp.link;
       }
       return result;
    } 
  4.  
    public void deleteFirst()
    {
       if (head == null)
          System.out.println("The list is empty, nothing to delete.");
       else if (head.link == null)
          head = null;
       else
       {
          Node temp = head.link;
          head.link = null;
          head = temp;
       }
    } 
  5.  
    public void deleteLast()
    {
       Node temp = head;
       if (head == null)
          System.out.println("The list is empty, nothing to delete.");
       else if (temp.link == null)
          head = null;
       else
       {
          while (temp.link.link != null)
          {
            temp = temp.link;
          }
          temp.link = null;
       }
    } 
  6.  
    public String toString()
    {
       Node temp = head;
       String result = "";
       if (head != null)
          while(temp != null)
          {
             result += temp.info;
             temp = temp.link;
             if (temp != null)
                result +="//";
          }
       return result;
    } 
  7.  
    public void addAtRear (int item)
    {
       Node temp = head;
       Node newNode = new Node();
       newNode.info = item;
       newNode.link = null;
       if (temp == null)
          head = newNode;
       else
       {
          while (temp.link != null)
          {
             temp = temp.link;
          }
          temp.link = newNode;
       }
    }