next up previous contents
Next: Delete an Element From Up: Overloaded I/O Methods: Previous: Building a List:

How Many Elements Are in the List?

    // *************************************** //
    // get the number of elements in the list  //
    // *************************************** //
int CHAR_DLLIST::get_number_elements()
{

  //cout << "entering get_number_of_elements " << endl;
  if(head==NULL) return(0);
  else{
    //cout << "head = " << *head;
    int i = 1;    
    CHAR_DL_CELL *again;
    again = head->next;
    while(!(again==NULL)){
      //cout << "again = " << *again;
      ++i;
      again = again->next;
      }
    //cout << "leaving get_number_of_elements " << endl;
    return(i);
    }
}



 

Jim Peterson
1999-04-22