Algorithm to count number of nodes, Data Structure & Algorithms

Write an algorithm to count number of nodes in the circular linked list.                           

Ans.

Counting No of Nodes in Circular List

Let list be a circular header list in memory. This algorithm traverse and counts number of nodes in a LIST.

0.   set COUNT: = 0

1. Set PTR: = LINK [START]. {Initializes the

pointer PTR}

2. Repeat steps 3, 4, 5 while PTR  =   START;

3. COUNT = COUNT + 1

4. Set PTR = LINK [PTR]. [PTR now points to next

node]

[End of step 2 loop]

5. Exit

 

Posted Date: 7/12/2012 8:27:44 AM | Location : United States







Related Discussions:- Algorithm to count number of nodes, Assignment Help, Ask Question on Algorithm to count number of nodes, Get Answer, Expert's Help, Algorithm to count number of nodes Discussions

Write discussion on Algorithm to count number of nodes
Your posts are moderated
Related Questions
Example 1:  Following are Simple sequence of statements Statement 1;  Statement 2; ... ... Statement k; The entire time can be found out through adding the times for

Part1: Deque and Bag Implementation First, complete the Linked List Implementation of the Deque (as in Worksheet 19) and Bag ADTs (Worksheet 22). Files Needed: linkedList.c Linke

What are circular queues?  Circular queue: Static queues have a very large drawback that once the queue is FULL, even though we erase few elements from the "front" and relieve

Question a) Describe how the endogenous model is an improvement to the neo-classical model in explaining the long-run effect of investment on economic growth of a country.

red black tree construction for 4,5,6,7,8,9

Determine the Disjoint of division method A polygon is disjoint from the viewport if the x- and y-extents of the polygon do not overlap the viewport anywhere. In this case; reg

Let us assume a file of 5 records that means n = 5 And k is a sorted array of keys of those 5 records. Let key = 55, low = 0, high = 4 Iteration 1: mid = (0+4)/2 = 2

The insertion procedure in a red-black tree is similar to a binary search tree i.e., the insertion proceeds in a similar manner but after insertion of nodes x into the tree T, we c

Write the algorithm for compound interest

Program segment for the deletion of any element from the queue delmq(i)  /* Delete any element from queue i */ { int i,x; if ( front[i] == rear[i]) printf("Queue is