Algorithm that counts number of nodes in a linked list, Data Structure & Algorithms

Q. Write an algorithm that counts number of nodes in a linked list.                                     

Ans.

Algorithm to Count No. of Nodes in Linked List

COUNT (INFO, LINK, START, NUM)

1. Set NUM: = 0 [initializes counter]

2. Set PTR=START [ initializes pointer]

3. Repeat steps 4 & 5 while PTR! = NULL

4. Set NUM:= NUM + 1 [ increases NUM by 1]

5. Set PTR: =LINK [PTR] . [updates pointer to point to next node]

[End of step 3 loop]

6. Return

 

 

Posted Date: 7/13/2012 2:10:41 AM | Location : United States







Related Discussions:- Algorithm that counts number of nodes in a linked list, Assignment Help, Ask Question on Algorithm that counts number of nodes in a linked list, Get Answer, Expert's Help, Algorithm that counts number of nodes in a linked list Discussions

Write discussion on Algorithm that counts number of nodes in a linked list
Your posts are moderated
Related Questions
b) The user will roll two (six-sided) dices and the user will lose the game if (s)he gets a value 1 on either any of the two dices & wins otherwise. Display a message to the user w

#questWrite an algorithm for multiplication of two sparse matrices using Linked Lists.ion..

explain working of siso-register to store 1011 and show timing diagram &table

What is tha flow chart of algorithm

It is a useful tool for indicating the logical properties of data type. It is a collection of values & a set of operations on those values. Methodically, "a TYPE is a set, & elemen

The process of accessing data stored in a serial access memory is same to manipulating data on a By using stack  method.

The minimum cost spanning tree has broad applications in distinct fields. It represents several complicated real world problems such as: 1. Minimum distance for travelling all o

Depth-first traversal A depth-first traversal of a tree visit a node and then recursively visits the subtrees of that node. Likewise, depth-first traversal of a graph visits

Suppose you are given the results of 5 games of rock-paper-scissors. The results are given to you on separate pieces of paper; each piece says either 'A' if the first person won, o

The operations of the Symbol ADT The operations of the Symbol ADT are the following. a==b-returns true if and only if symbols a and bare identical. a symbol bin Unico