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
Define Big Omega notation Big Omega notation (?) : The lower bound for the function 'f' is given by the big omega notation (?). Considering 'g' to be a function from the non-n

Let us assume a sparse matrix from storage view point. Assume that the entire sparse matrix is stored. Then, a significant amount of memory that stores the matrix consists of zeroe

Objectives The purpose of this project is to give you significant exposure to Binary Search Trees (BST), tree traversals, and recursive code. Background An arbitrary BST i

Book to refer: Introduction to Algorithms, 3rd Ed, by Clifford Stein, Thomas H. Cormen, Ronald Rivest, Charles E. Leiserson Question: Tic Tac Toe game -Design a GUI and implement

With the help of a program and a numerical example explain the Depth First Traversal of a tree.

Sequential files are most frequently utilized in commercial batch oriented data processing where there is the concept of a master file on which details are inserted periodically. F

characteristics of a good algorithm

A  BST is traversed in the following order recursively: Right, root, left e output sequence will be in In Descending order

CIRCULARLY LINKED LISTS IMPLEMENTATION A linked list wherein the last element points to the first element is called as CIRCULAR linked list. The chains do not specified first o

Hear is given a set of input representing the nodes of a binary tree, write a non recursive algorithm that must be able to give the output in three traversal orders. Write down an