Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
+1 vote
1.4k views
in Computer by (69.9k points)

What is a linked list? List different types of linked list. Write a C program to demonstrate a simple linear linked list. 

1 Answer

+2 votes
by (69.4k points)
selected by
 
Best answer

Linked list: A linked list is a self referential structure which contain a member field that point to the same structure type. In simple term, a linked list is collections of nodes that consists of two fields, one containing the information about that node, item and second contain the address of next node. Such a structure is represented as follows: 

struct node 

{ int item; 

struct node *next; 

};

Info part can be any of the data type; address part should always be the structure type. 

Linked lists are of following types:

1. Linear Singly linked list: A list type in which each node points to the next node and the last node points to NULL. 

2. Circular linked list: Lists which have no beginning and no end. The last node points back to the first item. 

3. Doubly linked list or Two-way linked list: These lists contain double set of pointers, one pointing to the next item and other pointing to the preceding item. So one can traverse the list in either direction. 

4. Circularly doubly linked list: It employs both the forward and backward pointer in circular form.

A program to demonstrate simple linear linked list is given below: 

#include < stdio. h>

#include < stdlib . h>

#define NULL 0

#define NULL 0

{

int number; 

struct linked_list *next;

};

typedef struct linked_list node;

void main()

{

node *head; 

void create(node *p);

int count(node *p);

void print(node *p);

clrscr();

head=(node *)malloc(sizeof(node));

create(head);

printf("\n");

print(head);

printf("\n");

printf("\n Number of items = %d \n",count(head));

getch();

}

void create(node *list)

{

printf("Input a number\n");

printf("(type -999 to end) : ");

scanf("%d",&list->number);

if(list->number == -999)

list->next=NULL;

else 

{

list->next=(node *)malloc(sizeof(node));

create(list->next);

}

return;

}

void print(node *list)

{

if(list->next!=NULL)

{

printf("%d - ->",list->number);

if(list->next->next == NULL)

printf("%d",list->next->number);

print(list->next);

}

return;

}

int count(node *list)

 if(list->next == NULL)

return(0);

else

return(1+count(list->next));

}

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...