Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
1.0k views
in Computer by (49.9k points)
closed by

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);

1 Answer

+1 vote
by (49.0k points)
selected by
 
Best answer

Algorithm 

Let P be a pointer of type listNodes. 

1. P = start, sum = 0 

2. Repeat steps 3, 4 while (P! = NULL) 

3. sum = sum + P → item 

4. P = P → next (end of step 2 loop) 

5. Return sum (Print sum)

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...