answersLogoWhite

0


Best Answer

Here is the required code.... to count the no. of nodes in a singly linked list..

#include < stdio.h>

#include < conio.h>

#include < malloc.h>

#include < process.h>

#include < ctype.h>

struct linear_list

{

int info;

struct linear_list *next;

}*start,*newnode,*ptr;

void main()

{

int item,num;

int i;

char ch;

clrscr();

newnode=(struct linear_list*)malloc(sizeof(struct linear_list));

start=newnode;

do

{

printf("\nEnter data: ");

scanf("%d",&item);

newnode->info=item;

printf("\nDo you want to create another node:(y/n)");

fflush(stdin);

scanf("%c",&ch);

if(tolower(ch)=='y')

{

newnode->next=(struct linear_list*)malloc(sizeof(struct linear_list));

newnode=newnode->next;

}

else

{

newnode->next=NULL;

}

}while(tolower(ch)!='n');

printf("\n Linked List is:\n");

ptr=start;

i=1;

while(ptr!=NULL)

{

printf("\nNode %d : %d",i,ptr->info);

ptr=ptr->next;

i++;

}

num=0;

ptr=start;

while(ptr!=NULL)

{

ptr=ptr->next;

num++;

}

printf("\nThe number of nodes in the linked list are: %d",num);

getch();

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program in 'C' language that counts the number of nodes in a singly linked list?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you write a program using function that counts the number of vowels in a string in java language?

Use text-editor notepad++


A program c plus plus on automorphic numbers or not?

how to write a program that counts automorphic number from 1 to 999


Program to count the number of numbers in an array using 8085 microprocessor?

A program which is used to count the number of numbers in an array using a 8085 microprocessor is known as a assembly language program.


An assembly language program that will take three decimal input and display minimum of them?

program that take three decimal number as input and find the largest among them in assembly language


The program will end when a 0 value is read This final value 0 will not participate in the required calculation?

Some people have realised that dividing by zero or 0 will not work. Any program which counts down from a large number to 0 wil stop the program.


What program can be written to count the number of alphanumerics in a string?

public int getStringLength(String val) { return val.length(); } There is an inbuilt functionality in strings that counts the number of alphabets in a string called length()


Could you write a assembly language program in tasm To check whether a given number present in a sequence of given memory location containing the string to be checked in 8086?

8086 assembly language program to check wether given number is perfect or not


What is counts in wool?

You may be thinking of counts in yarn, where counts can indicate the number of twists per inch in the spin.


How do you know if its a happy number?

It is not the number, it is how it is applied that counts


Write a programme for substraction of two numbers in c language?

substracion of any two number program in c


Even number progamm in c language?

swap(&amp;grades[num],&amp;grades[num+1]); what it make in a program?


What number is linked to this text plus number 6056093980?

It will probably be this number.