To count all elements of the circularly linked list, we will need a loop to traverse through the circularly linked list. We will let a link (i) of ListElem type to point to the pfirst then move the link 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 circularly linked list is reached.
// count the number of items in the list
public int countitem()
for (i = pfirst.next; i != pfirst; i = i.next)
t = t + 1;
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages: