Skip to main content

Linked List with Student Information & Count the Number of Node in C

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

#define NULL 0

struct linked_list
		{
		int roll;
		char name[20];
		struct linked_list *next;
		};
typedef struct linked_list node;

void create(node *list)
	{
	printf("Enter the ROLL NUMBER:\t");
	scanf("%d",&list->roll);
	if(list->roll<0)
		{
		list->next=NULL;
		}
	else
		{
		printf("Enter the NAME:\t");
		scanf("%c",list->name);
		list->next=(node *)malloc(sizeof(node));
		create(list->next);
		}
	return;
	}

void print(node *list)
	{
	if(list->next!=NULL)
		{
		printf("ROLL NO: %d\n",list->roll);
		printf("ROLL NO: %f\n",list->name);
		print(list->next);
		}
	return;
	}

int count(node *list)
	{
	if(list->next==NULL)
		return(0);
	else
		return(1+count(list->next));
	}
void main(void)
	{
	clrscr();
	node *head;
	head=(node *)malloc(sizeof(node));
	printf("\nTo QUIT, Enter any NEGATIVE NUMBER..\n");
	create(head);
	printf("\n\n");
	printf("\n\tPRINTING THR TOTAL LINK LIST.....");
	print(head);
	printf("THE NUMBER OF NODE IS %d",count(head));
	getch();
	}

Spread the love

Mashkawat Ahsan

I am Mashkawat Ahsan. Wikipedian, Mozillian, tech activist, art lover. Thank you for visiting.

Leave a Reply

Your email address will not be published. Required fields are marked *