Monday, December 9, 2013

Count the Number of Nodes in Singly Linked List

//count the no of elements in the list
int single_linked_list::no_of_elements()
{
    node* temp_node = first_node;
    int no_of_element = 0;
    while(temp_node!= NULL)
    {
      no_of_element++;
      temp_node = temp_node->link;
    }
    return no_of_element;
}

No comments: