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

Assignment Help:

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

 

 


Related Discussions:- Algorithm that counts number of nodes in a linked list

Procedure to delete all terminal nodes of the tree, Q. Let a binary tree 'T...

Q. Let a binary tree 'T' be in memory. Write a procedure to delete all terminal nodes of the tree.       A n s . fun ction to Delete Terminal Nodes from Binary Tree

The smallest element of an array''s index, The smallest element of an array...

The smallest element of an array's index is called its Lower bound.

Merge sort , What is the best-case number of comparisons performed by merge...

What is the best-case number of comparisons performed by mergesort on an input sequence of 2 k distinct numbers?

Binary search technique, Q. Describe the basic concept of binary search tec...

Q. Describe the basic concept of binary search technique? Is it more efficient than the sequential search?         Ans : The bin ary search technique:- This tec

Explain time complexity, Time Complexity:- The time complexity of an algori...

Time Complexity:- The time complexity of an algorithm is the amount of time it requires to run to completion. Some of the reasons for studying time complexity are:- We may be in

Explain multiplication method, Multiplication Method: The multiplication m...

Multiplication Method: The multiplication method operates in 2 steps. In the 1ststep the key value K is multiplied by a constant A in the range O

Stack, infix to revrse polish

infix to revrse polish

Write an algorithm outputs number of books using psuedocode, A shop sells b...

A shop sells books, maps and magazines. Every item is identified by a unique 4 - digit code. All books have a code starting with a 1, all maps have a code which starts with a 2 and

Psedocodes, write a pseudocode to input the top speed (in km''s/hours) of 5...

write a pseudocode to input the top speed (in km''s/hours) of 5000 cars output the fastest speed and the slowest speed output the average (mean) speed of all the 5000 cars answers

Program, What is a first-in-first-out data structure ? Write algorithms to...

What is a first-in-first-out data structure ? Write algorithms to perform the following operations on it – create, insertion, deletion, for testing overflow and empty conditions.

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd