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
Write a function that performs the integer mod function. Given the previous functions you have implemented already, this one should be a piece of cake. This function will find the

state difference between linear and non linear data structure. give one example scenario of each

QUESTION (a) Define a tree and list its properties. (b) By showing all your workings, draw the spanning tree for the following graph based on the Breadth-First-Search algori

Adjacency list representation An Adjacency list representation of Graph G = {V, E} contains an array of adjacency lists mentioned by adj of V list. For each of the vertex u?V,

Merge sort is also one of the 'divide & conquer' classes of algorithms. The fundamental idea in it is to split the list in a number of sublists, sort each of these sublists & merge

explain the prims''s algorithm with suitable example?

If a node in a BST has two children, then its inorder predecessor has No right child

You will write functions for both addition and subtraction of two numbers encoded in your data structure. These functions should not be hard to write. Remember how you add and subt

This algorithm inputs 3 numbers, every number goes through successive division by 10 until its value is less than 1. An output is produced which comprise the number input and a val

A full binary tree with n leaves have:- 2n -1 nodes.