UNIT IV
Linked list
• Each node in a linked list contains one or more members
that represent data.
• In addition to the data, each node contains a pointer,
which can point to another node.
Example
Data / Info link / next
Linked List.pptx
Advantages of Linked list over arrays:
• Efficient memory utilization
• Operations such as insertion and deletion are easy and
efficient.
• Size can be changed.
• Arbitrary memory locations
Disadvantages of linked lists:
• Each node requires an extra pointer in addition to
information, requiring more space.
• Insertion or deletion of a node takes a bit longer
because it involves more pointer operations.
• Linked lists do not allow random access.
• Traversing and changing of pointers consumes a lot of
time.
• Programming is typically trickier with pointers.
Memory Representation of Linear Linked List:
It needs two linear arrays for memory representation.
Let these linear arrays are INFO and LINK.
INFO[K] contains the information part and LINK[K]
contains the next pointer field of node K.
A variable START is used to store the location of the
beginning of the LIST
NULL is used as next pointer sentinel which indicates
the end of LIST.
Linked List.pptx
Linked List.pptx
Linked List.pptx
Linked List.pptx
TYPES OF LINKED LIST
Singly-linked list
• The simplest kind of linked list is a singly-linked
list which has one link per node. This link points to the
next node in the list, or to a null value or empty list if it
is the last node.
Doubly-linked list
• A more sophisticated kind of linked list is a doubly-
linked list. Each node has two links, one to the previous
node and one to the next node.
Doubly-linked list
• A more sophisticated kind of linked list is a doubly-
linked list. Each node has two links, one to the previous
node and one to the next node.
Info − Each link of a linked list can store a data
called an element.
Next − Each link of a linked list contains a link to
the next link called Next.
Prev − Each link of a linked list contains a link to
the previous link called Prev.
Advantages
1) It can be traversed in forward or backward
direction.
2) Given a particular nodes address, one can have
both successor nodes and predecessor nodes
address that makes inserting and deleting much
easier
3) It is used to represent the trees effectively.
Disadvantage
Extra memory is required to store the back pointer.
Circularly-linked list
• In a circularly-linked list, the first and last nodes
are linked together. This can be done for both
singly and doubly linked lists. To traverse a
circular linked list, you begin at any node and
follow the list in either direction until you return to
the original node. Viewed another way, circularly-
linked lists can be seen as having no beginning or
end.
Linked List.pptx
Singly –circularly linked list
• A singly linked circular list is a linked list where the last
node in the list points to the first node in the list. A
circular list does not contain NULL pointers
Doubly Linked List
In this type of liked list each node holds two-
pointer field. Pointers exist between adjacent
nodes in both directions. The list can be traversed
either forward or backward.
Linked List.pptx
Linked List.pptx
Linked List.pptx
Linked List.pptx
Linked List.pptx
Insertion at the Beginning of the list:
Linked List.pptx
Linked List.pptx
Linked List.pptx
• Single linked List
• Operations on Singly linked list:
– Traversing a linked list
– Creation of linked list
– Displaying elements of linked list
– counting number of nodes
– searching an element
– insertion of node
– deletion of node
void create()
{ char choice='y';
q=null; while(choice=='y')
{ p=((struct node*)malloc(sizeof(struct node)));
printf("nEnter the rollno & name :");
scanf("%d %s",&p->rollno,p->name);
p->prev=null;
p->next=null;
if(start==null) { start=p; q=p; }
else
{ q->next=p; p->prev=q; p->next=null; q=p; }
printf("nDo you want to create another node y/n :");
choice=getche();
} }
void display()
{
printf("n The nodes in the list arenSTART->");
p=start;
while(p!=null)
{
printf("%d %s ->",p->rollno,p->name);
p=p->next;
}
printf("NULL");
return;
}
void addatbeg()
{
p=((struct node*)malloc(sizeof(struct node)));
printf("nEnter register number:");
scanf("%d",&p->rollno);
printf("nEnter name of student:");
scanf("%s",&p->name);
(*start)->prev=p;
p->next=start;
p->prev=null;
start=p;
}
void addafter(int regno)
{ p=((struct node*)malloc(sizeof(struct node)));
printf("nEnter the rollno & name :");
scanf("%d %s",&p->rollno,p->name);
t=start;
while((t->next!=null)||(t->rollno==regno))
{ if(t->rollno==regno) break;
else t=t->next; }
if(t->next==null)
{ p->next=null; p->prev=t; t->next=p; }
else
{ p->prev=t; p->next=t->next; t->next=p;
}
}
void del(int regno)
{ p=start; prev=null;
if(start==null) {
printf("nLinked list is emptyn"); return; }
if(start->rollno==regno) {
start =start->link; free(p); return; }
while((p->rollno!=regno)&&(p!=null))
{ prev=p; p=p->link; }
if(p==null)
{ printf("n Reg number %d is not found in the LLn", regno); }
else { prev->link=p->link;
free(p);
}
}
void search(int regno)
{
int i=0; p=start;
while(p!=null)
{ if(regno==p->rollno)
{ i++;
printf("nRoll no %d is found at %d",p->rollno,i);
printf("n Name:%s",p->name);
return; }
else
{ p=p->link; i++; }
}
printf("nNode with register number %d does not exit",regno);
}
Stack Implementation using linked list:
/*Program to implement a Stack using Linked List */
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define NULL 0
void push(int);
int pop();
void display();
struct node
{
int info;
struct node *link;
}*top,*p;
void main()
{
int ch,i,item,pos;
clrscr();
while(1)
{ printf("n1->Pushn");
printf("2->Popn");
printf("3->Displayn");
printf("4->Exitn");
printf("Enter your choicen");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("enter an elementn");
scanf("%d",&item);
push(item);
break;
case 2:item=pop();
if(item==-1)
printf("Empty Stackn");
else
printf("Popped element=%dn",item); break;
case 3:display();
break;
case 4:exit(0);
} } }
void push(int item)
{
p=(struct node *)malloc(sizeof(struct node));
p->info=item;
p->link=NULL;
if(top==NULL)
top=p;
else
{ p->link=top;
top=p; } }
int pop()
{
int delinfo;
p=top;
if(p==NULL)
return(-1);
top=top->link;
delinfo=p->info;
free(p);
return(delinfo);
}
void display()
{
p=top;
if(p==NULL)
printf("empty Stackn");
else
printf("nStackn");
while(p!=NULL) {
printf("%dt",p->info);
p=p->link;
} }
Circular Linked list
Circular Linked List is a variation of Linked list in which the
first element points to the last element and the last element
points to the first element. Both Singly Linked List and
Doubly Linked List can be made into a circular linked list.
Circular Linked list
void insert(int item)
{
p=(struct node *)malloc(sizeof(struct node));
p->info=item;
p->link=NULL;
if(front==NULL)
front=p;
else
rear->link=p;
rear=p;
rear->link=front;
}
int delet()
{
int delinfo;
if(front==NULL)
return(-1);
else
{
if(front==rear)
{
delinfo=front->info;
free(front);
front=NULL;
rear=NULL;
}
else
{
p=front;
delinfo=p->info;
front=front->link;
rear->link=front;
free(p);
}
return(delinfo);
} }
void display()
{
p=front;
if(p==NULL)
printf("empty Listn");
else
printf("Circular Linked Listn");
while(p!=rear)
{
printf("%dt",p->info);
p=p->link;
}
printf("%dn",p->info);
}
Stack Implementation using linked list:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define NULL 0
void push(int);
int pop();
void display();
struct node
{
int info;
struct node *link;
}*top,*p;
void main()
{
int ch,i,item,pos;
clrscr();
while(1)
{
printf("n1->Pushn");
printf("2->Popn");
printf("3->Displayn");
printf("4->Exitn");
printf("Enter your choicen");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("enter an elementn");
scanf("%d",&item);
push(item);
case 2:item=pop();
if(item==-1)
printf("Empty Stackn");
else
printf("Popped element=%dn",item);
break;
case 3:display();
break;
case 4:exit(0);
}
}
}
void push(int item)
{
p=(struct node *)malloc(sizeof(struct node));
p->info=item;
p->link=NULL;
if(top==NULL)
top=p;
else
{
p->link=top;
top=p;
}
}
int pop()
{
int delinfo;
p=top;
if(p==NULL)
return(-1);
top=top->link;
delinfo=p->info;
free(p);
return(delinfo);
}
void display()
{
p=top;
if(p==NULL)
printf("empty Stackn");
else
printf("nStackn");
while(p!=NULL)
{
printf("%dt",p->info);
p=p->link;
}
}

More Related Content

PDF
DS Module 03.pdf
PPT
ANOITO2341988888888888888888888885555.ppt
PPT
Link list using array in Data structure amd algorithms
PPT
DS Unit 2.ppt
PPTX
Deleting a node from the list(SINGLE LINKED LIST)
PPTX
Data Structures-UNIT Four_Linked_List.pptx
PPT
Linked List
PPTX
Linked Lists, Single Linked list and its operations
DS Module 03.pdf
ANOITO2341988888888888888888888885555.ppt
Link list using array in Data structure amd algorithms
DS Unit 2.ppt
Deleting a node from the list(SINGLE LINKED LIST)
Data Structures-UNIT Four_Linked_List.pptx
Linked List
Linked Lists, Single Linked list and its operations

Similar to Linked List.pptx (20)

PPTX
linked list.pptxdj bdjbhjddnbfjdndvdhbfvgh
PPTX
module 3-.pptx
PPTX
Linked List
PPT
Unit ii(dsc++)
DOCX
Link list assi
PPTX
DSModule2.pptx
PPTX
Ll.pptx
PPTX
linked list.pptx
PPTX
Linked List in Data Structure
PPTX
Linear Data Structures - List, Stack and Queue
PPTX
Data Structures(Part 1)
PPTX
Data structures2
PPTX
linkedlist.pptx
PPTX
Data Structures Introduction & Linear DS
PPTX
linkedlistforslideshare-210123143943.pptx
PPTX
Linked list
DOCX
Linked list.docx
PDF
Linked list (introduction) 1
linked list.pptxdj bdjbhjddnbfjdndvdhbfvgh
module 3-.pptx
Linked List
Unit ii(dsc++)
Link list assi
DSModule2.pptx
Ll.pptx
linked list.pptx
Linked List in Data Structure
Linear Data Structures - List, Stack and Queue
Data Structures(Part 1)
Data structures2
linkedlist.pptx
Data Structures Introduction & Linear DS
linkedlistforslideshare-210123143943.pptx
Linked list
Linked list.docx
Linked list (introduction) 1
Ad

More from SherinRappai (20)

PPTX
Shells commands, file structure, directory structure.pptx
PPTX
Shell Programming Language in Operating System .pptx
PPTX
Types of NoSql Database available.pptx
PPTX
Introduction to NoSQL & Features of NoSQL.pptx
PPTX
Clustering, Types of clustering, Types of data
PPTX
Association rule introduction, Market basket Analysis
PPTX
Introduction to Internet, Domain Name System
PPTX
Cascading style sheet, CSS Box model, Table in CSS
PPTX
Numpy in python, Array operations using numpy and so on
PPTX
Functions in python, types of functions in python
PPTX
Extensible markup language ppt as part of Internet Technology
PPTX
Java script ppt from students in internet technology
PPTX
Building Competency and Career in the Open Source World
PPTX
How to Build a Career in Open Source.pptx
PPTX
Issues in Knowledge representation for students
PPTX
A* algorithm of Artificial Intelligence for BCA students
PPTX
Unit 2.pptx
PPTX
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
PPTX
Clustering.pptx
PPTX
neuralnetwork.pptx
Shells commands, file structure, directory structure.pptx
Shell Programming Language in Operating System .pptx
Types of NoSql Database available.pptx
Introduction to NoSQL & Features of NoSQL.pptx
Clustering, Types of clustering, Types of data
Association rule introduction, Market basket Analysis
Introduction to Internet, Domain Name System
Cascading style sheet, CSS Box model, Table in CSS
Numpy in python, Array operations using numpy and so on
Functions in python, types of functions in python
Extensible markup language ppt as part of Internet Technology
Java script ppt from students in internet technology
Building Competency and Career in the Open Source World
How to Build a Career in Open Source.pptx
Issues in Knowledge representation for students
A* algorithm of Artificial Intelligence for BCA students
Unit 2.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
Clustering.pptx
neuralnetwork.pptx
Ad

Recently uploaded (20)

PDF
UiPath Agentic Automation session 1: RPA to Agents
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PPTX
Chapter 5: Probability Theory and Statistics
PPTX
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
The influence of sentiment analysis in enhancing early warning system model f...
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
1 - Historical Antecedents, Social Consideration.pdf
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PPTX
Configure Apache Mutual Authentication
PDF
Convolutional neural network based encoder-decoder for efficient real-time ob...
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPTX
Modernising the Digital Integration Hub
PDF
Flame analysis and combustion estimation using large language and vision assi...
PDF
Architecture types and enterprise applications.pdf
PPT
What is a Computer? Input Devices /output devices
DOCX
search engine optimization ppt fir known well about this
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
Five Habits of High-Impact Board Members
UiPath Agentic Automation session 1: RPA to Agents
A contest of sentiment analysis: k-nearest neighbor versus neural network
Chapter 5: Probability Theory and Statistics
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
sustainability-14-14877-v2.pddhzftheheeeee
The influence of sentiment analysis in enhancing early warning system model f...
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
1 - Historical Antecedents, Social Consideration.pdf
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Configure Apache Mutual Authentication
Convolutional neural network based encoder-decoder for efficient real-time ob...
NewMind AI Weekly Chronicles – August ’25 Week III
A comparative study of natural language inference in Swahili using monolingua...
Modernising the Digital Integration Hub
Flame analysis and combustion estimation using large language and vision assi...
Architecture types and enterprise applications.pdf
What is a Computer? Input Devices /output devices
search engine optimization ppt fir known well about this
Final SEM Unit 1 for mit wpu at pune .pptx
Five Habits of High-Impact Board Members

Linked List.pptx