﻿ C++ exercises solutions: count elements of linked list

C++ exercises solutions: count elements of linked list

Circularly Linked List

Count elements of circularly linked list

Step 3: Count elements of the circularly linked list

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 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 circularly linked list is reached.

//C++ code to count the number of items in the list
int countitem(ListElem *L)
{
ListElem *i;
int t;
i=L;
if(L!=NULL){
t=1;
i=i->next;
while(i!=L){ //not the end of the list
t=t+1;
i=i->next;

}
return t;
}

else return 0;

}

Comments

 Henish patelPlease Help me with this problem..!! Write a procedure Split1(A, NA, B, NB, C, NC) that copies elements of an array A of NA real numbers to arrays B and C so that the array B contains all elements of the array A with odd order numbers (1, 3, …) and the array C contains all elements of the array A with even order numbers (2, 4, …). The arrays B, C and their sizes NB, NC are output parameters. Apply this procedure to a given array A of size NA and output the size and the elements for each of the resulting arrays B and C.2017-05-25

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.