Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
1.6k views
in Computer by (48.9k points)
closed by

A linked list is formed from the objects of the class:

class Node

int item; 

Node next; 

Write an Algorithm OR a Method to count the number of nodes in the linked list. The method declaration is given below: 

int count (Node ptr-start)

1 Answer

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

Algorithm to count the number of nodes in a linked list Steps: 

1. Start 

2. Set a temporary pointer to the first node and counter to 0. 

3. Repeat steps 4 and 5 until the pointer reaches null 

4. Increment the counter 

5. move the temporary pointer to the next node 

6. Return the counter value 

7. End 

Method to count for the number of nodes in a linked list

int count (Node ptr_start) 

Node a = new Node(ptr_start); 

int c=0; 

while (a!=null) 

{ c++; a=a.next; 

return c: 

}

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

...