SlideShare a Scribd company logo
1 of 51
Download to read offline
DATASTRUCTURE
DATRUCTURE IS THE WAY OF
ORGANIZING ALL DATA ITEMS IN
ORDER THAT NOT ONLY ELEMENTS TO
BE STORED BUT ALSO THE RELATION
BETWEEN THE ELEMENTS
DATASTRUCTURE
LINEAR
LINKLIST
ARRAY
STACK
QUEUE
NONLINEAR
TREES&
GRAPH
Linked List
What are the problems with Arrays
- Size is fixed
-Array Items are stored contiguously
-Insertions and deletion at particular position is complex
Why Linked list ?
-Size is not fixed
-Data can be stored at any place
-Insertions and deletions are simple and faster
What is Linked List?
A linked list is a collection of nodes with various fields
It contains data field and Address field or Link field
Info field
Link Field/
Address Field
Pointer to the
first node
Linked List Types
Singly Linked list
Circular singly linked list
Doubly linked lists
Circular doubly linked lists
Graphical Representation
10
1000
1000
2000
2000
15 NULL
20
4000
Singly Linked List
First
Graphical Representation
10
1000
1000
2000
2000
15 4000
20
4000
Circular Singly Linked List
Last node contains the address of the first node
First
Doubly Linked list
Contains the address of previous node
and next node
NULL
2000 3000
1000
10 15 20
2000 1000 2000 NULL
3000
First
Circular Doubly Linked list
Contains the address of first node and
last node
3000
2000 3000
1000
10 15 20
2000 1000 2000 1000
3000
First
Representation of Singly Linked list
struct node
{
int info;
struct node *link
};
typedef struct node *NODE;
Meaning of this: A node is of the type struct and
contains info field and link filed
What is typedef ?
typedef is a keyword in the C Language used to give
the new name to data types
The intent is to make it easier for programmers
Example typedef int x;
Later on you can use x as a data type
x a, b;
Means a and b are variables of the type integer
Graphical Representation
10
1000
1000
2000
2000
15 NULL
20
4000
Operations on Singly Linked List
First
Insert
Delete
Display the contents
Allocation of memory to newnode
newnode =( NODE ) malloc (sizeof(struct node));
It Returns address of the location with piece of
memory of the size struct. That is for information
field and address field
Algorithm to Insert an Element from the front
1 temp=allocate memory
2 temp(info)=item;
3 link(temp)=first;
4 call temp as first
5 temp <- newnode
6 return first;
temp
30
Temp node with item
NULL
NULL NULL
10
1000
1000
2000
2000
15 NULL
20
4000
Operations on Singly Linked List
Insert from the front
First
temp
temp->link=first,
10
1000
1000
2000
2000
15 NULL
20
4000
Operations on Singly Linked List
Insert from the front
First
first=temp
Algorithm to Display the content
// Algorithm Display
if (first==NULL)
write list empty
return;
Write “ Contents of the List ”
temp=first
While(temp!=NULL)
{
write (info(temp))
temp=link(temp)
}
C Function to Insert an Element from
the front
Insertfront(NODE first int item)
{
NODE temp;
temp=(NODE) malloc(sizeof(struct node));
temp->info=item;
temp->link=NULL ;
temp->link=first;
first=temp;
return(temp);
}
Algorithm to Delete from the front
1 if (first==NULL)
2 Write list empty and return first
3 temp=first
4 first=link(first)
5 free(temp)
6 return(first)
C Function to Delete the element from the
front
NODE deletefront(NODE first)
{
if (first==NULL)
{ printf(List is empty..n”);
return first;
}
temp=first;
first=first->link;
printf(“ The ietm deleted is %d”,temp->info);
free(temp);
return(first);
}
10
1000
1000
2000
2000
15 NULL
20
4000
Operations on Singly Linked List
Delete from the front
Temp/
First
temp=first
10
1000
1000
2000
2000
15 NULL
20
4000
Operations on Singly Linked List
Delete from the front
First
temp
temp=first, first=first->link
1000 2000
2000
15 NULL
20
Operations on Singly Linked List
Delete from the front
First
Stack Using Linked List
CONCEPT : LIFO
Inserting an element from front and
deleting an element from front is nothing
but STACK
30 Null
top
3000
Push item 30
S
T
A
C
K
L
I
N
K
E
D
L
I
S
T
30 Null
top
20
3000
2000
3000
Push item 20
30 Null
top
20
3000
2000 3000
10
2000
1000
Push item 10
30 Null
top
20
3000
2000 3000
POP 10
30 Null
top
3000
POP 20
POP 30
STACK EMPTY
Inserting an Element from the rear and deleting
An element from the front is nothing but Q
Implementation of Q using Linked List
20
temp
Front=null
Front=rear=temp
NULL
Insert 20
20
Inserting 20
NULL
Front/
Rear
20
front/rear
Inserting 30
NULL
rear->link=temp
temp
30 null
2000
20
front
Inserting 30
2000
rear->link=temp
rear=temp
rear
30 null
2000
1000
20
front
Inserting 40
2000
rear->link=temp
rear=temp
rear
30 null
2000
1000
40 Null
20
front
Inserting 40
2000
rear->link=temp
rear=temp
rear
30 3000
2000
1000
40 Null
3000
20
front
Deleting 20
2000
temp=front
front=front->link
free(temp)
rear
30 3000
2000
1000
40 Null
3000
Delete Operation
front
Deleting 30
rear
30 3000
2000
40 Null
3000
front
Deleting 40
rear
40 Null
3000
Q Empty
10
1000
1000
2000
2000
15 NULL
20
4000
Searching an Item in a
Singly Linked List
first
Cur=first
Pos=1;
while(cur!=NULL && item!=cur->info)
cur=cur->link;
pos++;
key=20
cur
Cur->info=10
10
1000
1000
2000
2000
15 NULL
20
4000
Searching an Item in a
Singly Linked List
key =30
First
Cur=first
Pos=1;
while(cur!=NULL && item!=cur->info)
cur=cur->link;
pos++;
Cur
Cur->info = 15 Key=30
10
1000
1000
2000
2000
15 NULL
20
4000
Searching an Item in a
Singly Linked List
First
Cur=first
Pos=1;
while(cur!=NULL && item!=cur->info)
cur=cur->link;
pos++;
Cur
Now Item = 20 , key found at position =3
C Function to search an Item in the list
NODE search(NODE first, int key)
{
NODE cur;
int pos;
if(first==NULL)
{ printf(“ List Empty Search Not Possible…..n”);
return;
}
Cur=first;
pos=1;
while( cur != NULL && key!=cur->info)
{
cur=cur->link;
If(cur==NULL)
printf(“ Item not found…n”);
else
printf(“ Item found at position .. %d”,pos);
}
Inserting an Element at any Position
10 20
2000
2000 NULL
21 ANIL 03
2000
2000 22 sunil 3 NULL
first
Each Student Record in a Node
1000
Representation of the Record using Linked List
struct student
{
int id;
char name[20];
int sem;
struct student link;
};
typedef struct student *NODE;
dokumen.tips_linked-list-ppt-5584a44be6115.pptx

More Related Content

Similar to dokumen.tips_linked-list-ppt-5584a44be6115.pptx

Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arorakulachihansraj
 
Stacks & Queues
Stacks & QueuesStacks & Queues
Stacks & Queuestech4us
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringRAJASEKHARV8
 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.pptAlliVinay1
 
Data Structure -List Stack Queue
Data Structure -List Stack QueueData Structure -List Stack Queue
Data Structure -List Stack Queuesurya pandian
 
Data structures & algorithms lecture 3
Data structures & algorithms lecture 3Data structures & algorithms lecture 3
Data structures & algorithms lecture 3Poojith Chowdhary
 
LINKED LIST IN C++ +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
LINKED LIST IN C++ +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUSLINKED LIST IN C++ +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
LINKED LIST IN C++ +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUSVenugopalavarma Raja
 
Array linked list.ppt
Array  linked list.pptArray  linked list.ppt
Array linked list.pptWaf1231
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueRai University
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queueRai University
 
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDev Chauhan
 
Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Getachew Ganfur
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queueRai University
 

Similar to dokumen.tips_linked-list-ppt-5584a44be6115.pptx (20)

Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
 
Stacks & Queues
Stacks & QueuesStacks & Queues
Stacks & Queues
 
Linked list
Linked listLinked list
Linked list
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.ppt
 
Data Structure -List Stack Queue
Data Structure -List Stack QueueData Structure -List Stack Queue
Data Structure -List Stack Queue
 
Data structure
Data structureData structure
Data structure
 
Data structures & algorithms lecture 3
Data structures & algorithms lecture 3Data structures & algorithms lecture 3
Data structures & algorithms lecture 3
 
LINKED LIST IN C++ +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
LINKED LIST IN C++ +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUSLINKED LIST IN C++ +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
LINKED LIST IN C++ +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
 
Array linked list.ppt
Array  linked list.pptArray  linked list.ppt
Array linked list.ppt
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
 
List
ListList
List
 
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
 
Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9
 
Rana Junaid Rasheed
Rana Junaid RasheedRana Junaid Rasheed
Rana Junaid Rasheed
 
3.ppt
3.ppt3.ppt
3.ppt
 
3.ppt
3.ppt3.ppt
3.ppt
 
Chapter 5 ds
Chapter 5 dsChapter 5 ds
Chapter 5 ds
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
 

Recently uploaded

Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 

Recently uploaded (20)

Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 

dokumen.tips_linked-list-ppt-5584a44be6115.pptx