C++ exercises and solutions- doubly linked list count elements

C++ OOP: Doubly Linked List

Count elements of doubly linked list

Step 3: Count elements of the doubly linked list

To count all elements of the doubly linked list, we will need a loop to traverse through the doubly linked list. We will let a pointer (i) of ListElem type to point to the pfirst then move the pointer to its next element and increase the number of item(t) one at a time by using a while loop until the end of the doubly linked list is reached.

//Count the number of items in the doubly linked list

template <class Type>
int LinkedList<Type>::countitem()
  ListElem<Type> *i;
  int t=0;
  return t;


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.