icse-promo

Question

A linked list is formed from the objects of the class ,
class ListNodes
{
int item;
ListNodes next;
}
Write a method OR an algorithm to compute and return the sum of all integers items stored in the linked list .The method declaration is specified below:
int listsum(ListNodes start);

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					
int listsum(ListNodes start)
{
    int total=0;
    ListNodes runner=start; 
    while(runner!=null)
    {
        total +=runner.item;
        runner=runner.next;
    }
    return total;
}


				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *