SlideShare a Scribd company logo
1 of 26
Download to read offline
LINKEDLIST
MODULE 3
Dr. SINDHIA LINGASWAMY, VIT 1
TOPICS COVERED
• Definition
• Representation of linked list
• Operations of linked list
• Implementation of the list
• Array implementation
• Linked list implementation
• Cursor implementation
• Ajflajf
Dr. SINDHIA LINGASWAMY, VIT 2
DEFINITION
• Linear collection of data elements called nodes.
• Linked list is a sequence of links which contains items. Each link contains
a connection to another link.
• Important terms to understand the concept of linked list.
• Link − 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.
• Linked list − a linked list contains the connection link to the first link
called first.
Dr. SINDHIA LINGASWAMY, VIT 3
REPRESENTATION OF LINKED LIST
Dr. SINDHIA LINGASWAMY, VIT 4
H D1
NEXT
D2
NEXT
D3
NEXT
• Linked List contains a link element called first / Header.
• Each node carries a data field(s) and a link field called next.
• Each node is linked with its next node using its next link.
• Last node carries a link as null to mark the end of the list.
OPERATIONS
• The basic operations supported by a list.
• Insert(X,Y) − insert an element X at the position Y.
• Deletion(X) − deletes an element X.
• Find(X) − Returns the position of X
• Next (i) – Returns the position of its successor element i+1
• Previous (i)- Returns the position of its predecessor i-1
• Display − Print the complete list.
• MakeEmpty − Makes the list empty.
Dr. SINDHIA LINGASWAMY, VIT 5
TYPES OF LINKED LIST
•Singly linked list
•Doubly linked list
•Circular linked list
Dr. SINDHIA LINGASWAMY, VIT 6
SINGLY LINKED LIST
• A linked list which each node contains only one link positioning to
the next node in the list.
Dr. SINDHIA LINGASWAMY, VIT 7
H 10 20 30
20 30 4010
DECLARATION OF LINKED LIST
Struct node;
typedef struct Node *List;
typedef struct Node *Position;
int IsLast( Position P, List L);
int IsEmpty(List L);
position Find (int X, List L);
void Delete (int X, List L);
position FindPrev(int X, List L);
position FindNext(int X, List L);
void Insert(int X, List L, Position P);
void DeleteList(List L);
Struct Node
{
int element;
position Next;
}
Dr. SINDHIA LINGASWAMY, VIT 8
INSERTION
void Insert ( int X, List L, Position P)
{
position Newnode;
Newnode = malloc(size of (Struct Node));
if (Newnode != NULL )
{
Newnode → Element = X;
Newnode → Next = P → Next ;
P → Next = Newnode;
}
}
Dr. SINDHIA LINGASWAMY, VIT 9
Dr. SINDHIA LINGASWAMY, VIT 10
H 10 20 30
15
P
Newnode
ISEMPTY
• Check whether the list is empty
int IsEmpty ( List L )
{
if ( L → Next == NULL )
return (1);
}
Empty List
Dr. SINDHIA LINGASWAMY, VIT 11
Header L
ISLAST
• Check whether the current position is last.
int IsLast ( position P, List L )
{
if ( P → Next == NULL);
return (1);
P
}
Dr. SINDHIA LINGASWAMY, VIT 12
L 10 20 30
FIND
•Returns the position of X
position Find (int X, List L)
{
position P;
P = L → Next ;
while ( P ! = NULL && P → Element ! = X)
P = P → Next;
return P; P
}
Dr. SINDHIA LINGASWAMY, VIT 13
L 10 20 30
PREVIOUS
position FindPrev (int X, List L)
{
position P;
P = L;
while ( P → Next ! = NULL && P → Next → Element != X)
P = P → Next ;
return P;
}
P X
Dr. SINDHIA LINGASWAMY, VIT 14
L 10 20 30
FINDNEXT
position FindNext ( int X, List L)
{
P = L → Next;
while ( P → Next ! = NULL && P → Element ! = X)
P = P → Next ;
return P → Next;
}
X, P P → Next
Dr. SINDHIA LINGASWAMY, VIT 15
L 10 20 30
Delete an Element
void Delete (int X, List L)
{ X
position P, Temp;
P = FindPrev( X,L );
if ( ! IsLast ( P, L)) P Temp
{
Temp = P → Next;
P → Next = Temp → Next;
Free (Temp);
}
}
Dr. SINDHIA LINGASWAMY, VIT 16
L 10 20 30
L 10 30
DELETE THE LIST
Void DeleteList ( List L)
{
position P, Temp;
P = L → Next;
L → Next = NULL;
while ( P ! = NULL )
{
Temp = P → Next;
free (P);
P = Temp;
}
}
Dr. SINDHIA LINGASWAMY, VIT 17
Dr. SINDHIA LINGASWAMY, VIT 18
L 10 30
10 30
30
L → Next = NULL
Temp = P → Next
P
P Temp
Free ( P )
P = Temp
Temp , P = NULL
DOUBLY LINKED LIST
◦ Doubly linked list is a linked data structure that consists of a set of
sequentially linked records called nodes.
◦ Each node contains three fields
◦ one is data part which contain data only.
◦ two other field is links part that are point or references to the
previous or to the next node in the sequence of nodes.
◦ The beginning and ending nodes' previous and next links,
respectively, point to some kind of terminator, typically a sentinel
node or null to facilitate traversal of the list.
Dr. SINDHIA LINGASWAMY, VIT 19
REPRESENTATION
Dr. SINDHIA LINGASWAMY, VIT 20
20 300 1000 30 5700 300 40
COMPARED WITH SLL
◦ Advantages
◦ Can be traversed in either direction (may be essential for some
programs)
◦ Some operations, such as deletion and inserting before a node,
become easier
◦ Disadvantages
◦ Requires more space
◦ List manipulations are slower (because more links must be changed)
◦ Greater chance of having bugs (because more links must be
manipulated) Dr. SINDHIA LINGASWAMY, VIT 21
INSERTION
Dr. SINDHIA LINGASWAMY, VIT 22
20 30 40
H
25
L
P
NEW NODE
ROUTINE – INSERTION
void Insert ( int X, list L, position P )
{
Struct Node *Newnode;
Newnode = malloc )sizeof (Struct Node));
If ( Newnode ! = NULL )
{
Newnode → Element = X;
Newnode → Flink = P → Flink;
P→Flink→Blink = Newnode;
P→Flink = Newnode;
Newnode →Blink = P;
} } Dr. SINDHIA LINGASWAMY, VIT 23
DELETION
Dr. SINDHIA LINGASWAMY, VIT 24
20 30 40
H
P
ROUTINE – DELETION
void Delete ( int X, List L)
{
position P;
P = Find(X,L);
if ( IsLast(P,L))
{
Temp = P ;
P→Blink→Flink – NULL;
free (Temp);
}
else
{
Temp = P;
P→Blink →Flink = P →Flink;
P→Flink→Blink = P→Blink;
Free (Temp);
}
}
Dr. SINDHIA LINGASWAMY, VIT 25
CIRCULAR LINKED LIST
• The pointer of the las t node points to the first node
• Can be implemented as
• Singly linked circular list
• Doubly linked circular list
Dr. SINDHIA LINGASWAMY, VIT 26
5700 20 300 1000 30 5700 300 40 1000
10 20 30

More Related Content

Similar to Liked Lists

Similar to Liked Lists (20)

Deletion from single way linked list and search
Deletion from single way linked list and searchDeletion from single way linked list and search
Deletion from single way linked list and search
 
Unit - 2.pdf
Unit - 2.pdfUnit - 2.pdf
Unit - 2.pdf
 
Circular_Linked_List.ppt
Circular_Linked_List.pptCircular_Linked_List.ppt
Circular_Linked_List.ppt
 
Linked list and its operations - Traversal
Linked list and its operations - TraversalLinked list and its operations - Traversal
Linked list and its operations - Traversal
 
Data structures & algorithms lecture 3
Data structures & algorithms lecture 3Data structures & algorithms lecture 3
Data structures & algorithms lecture 3
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
 
Algo>ADT list & linked list
Algo>ADT list & linked listAlgo>ADT list & linked list
Algo>ADT list & linked list
 
Singly Linked List
Singly Linked ListSingly Linked List
Singly Linked List
 
csc211_lecture_21.pptx
csc211_lecture_21.pptxcsc211_lecture_21.pptx
csc211_lecture_21.pptx
 
LINKED LIST.pptx
LINKED LIST.pptxLINKED LIST.pptx
LINKED LIST.pptx
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
 
Linked lists
Linked listsLinked lists
Linked lists
 
Array linked list.ppt
Array  linked list.pptArray  linked list.ppt
Array linked list.ppt
 
List
ListList
List
 
linked-list.ppt
linked-list.pptlinked-list.ppt
linked-list.ppt
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
 
Team 9
Team 9Team 9
Team 9
 
Linked List
Linked ListLinked List
Linked List
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
Linked list
Linked list Linked list
Linked list
 

Recently uploaded

Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 

Recently uploaded (20)

Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 

Liked Lists

  • 2. TOPICS COVERED • Definition • Representation of linked list • Operations of linked list • Implementation of the list • Array implementation • Linked list implementation • Cursor implementation • Ajflajf Dr. SINDHIA LINGASWAMY, VIT 2
  • 3. DEFINITION • Linear collection of data elements called nodes. • Linked list is a sequence of links which contains items. Each link contains a connection to another link. • Important terms to understand the concept of linked list. • Link − 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. • Linked list − a linked list contains the connection link to the first link called first. Dr. SINDHIA LINGASWAMY, VIT 3
  • 4. REPRESENTATION OF LINKED LIST Dr. SINDHIA LINGASWAMY, VIT 4 H D1 NEXT D2 NEXT D3 NEXT • Linked List contains a link element called first / Header. • Each node carries a data field(s) and a link field called next. • Each node is linked with its next node using its next link. • Last node carries a link as null to mark the end of the list.
  • 5. OPERATIONS • The basic operations supported by a list. • Insert(X,Y) − insert an element X at the position Y. • Deletion(X) − deletes an element X. • Find(X) − Returns the position of X • Next (i) – Returns the position of its successor element i+1 • Previous (i)- Returns the position of its predecessor i-1 • Display − Print the complete list. • MakeEmpty − Makes the list empty. Dr. SINDHIA LINGASWAMY, VIT 5
  • 6. TYPES OF LINKED LIST •Singly linked list •Doubly linked list •Circular linked list Dr. SINDHIA LINGASWAMY, VIT 6
  • 7. SINGLY LINKED LIST • A linked list which each node contains only one link positioning to the next node in the list. Dr. SINDHIA LINGASWAMY, VIT 7 H 10 20 30 20 30 4010
  • 8. DECLARATION OF LINKED LIST Struct node; typedef struct Node *List; typedef struct Node *Position; int IsLast( Position P, List L); int IsEmpty(List L); position Find (int X, List L); void Delete (int X, List L); position FindPrev(int X, List L); position FindNext(int X, List L); void Insert(int X, List L, Position P); void DeleteList(List L); Struct Node { int element; position Next; } Dr. SINDHIA LINGASWAMY, VIT 8
  • 9. INSERTION void Insert ( int X, List L, Position P) { position Newnode; Newnode = malloc(size of (Struct Node)); if (Newnode != NULL ) { Newnode → Element = X; Newnode → Next = P → Next ; P → Next = Newnode; } } Dr. SINDHIA LINGASWAMY, VIT 9
  • 10. Dr. SINDHIA LINGASWAMY, VIT 10 H 10 20 30 15 P Newnode
  • 11. ISEMPTY • Check whether the list is empty int IsEmpty ( List L ) { if ( L → Next == NULL ) return (1); } Empty List Dr. SINDHIA LINGASWAMY, VIT 11 Header L
  • 12. ISLAST • Check whether the current position is last. int IsLast ( position P, List L ) { if ( P → Next == NULL); return (1); P } Dr. SINDHIA LINGASWAMY, VIT 12 L 10 20 30
  • 13. FIND •Returns the position of X position Find (int X, List L) { position P; P = L → Next ; while ( P ! = NULL && P → Element ! = X) P = P → Next; return P; P } Dr. SINDHIA LINGASWAMY, VIT 13 L 10 20 30
  • 14. PREVIOUS position FindPrev (int X, List L) { position P; P = L; while ( P → Next ! = NULL && P → Next → Element != X) P = P → Next ; return P; } P X Dr. SINDHIA LINGASWAMY, VIT 14 L 10 20 30
  • 15. FINDNEXT position FindNext ( int X, List L) { P = L → Next; while ( P → Next ! = NULL && P → Element ! = X) P = P → Next ; return P → Next; } X, P P → Next Dr. SINDHIA LINGASWAMY, VIT 15 L 10 20 30
  • 16. Delete an Element void Delete (int X, List L) { X position P, Temp; P = FindPrev( X,L ); if ( ! IsLast ( P, L)) P Temp { Temp = P → Next; P → Next = Temp → Next; Free (Temp); } } Dr. SINDHIA LINGASWAMY, VIT 16 L 10 20 30 L 10 30
  • 17. DELETE THE LIST Void DeleteList ( List L) { position P, Temp; P = L → Next; L → Next = NULL; while ( P ! = NULL ) { Temp = P → Next; free (P); P = Temp; } } Dr. SINDHIA LINGASWAMY, VIT 17
  • 18. Dr. SINDHIA LINGASWAMY, VIT 18 L 10 30 10 30 30 L → Next = NULL Temp = P → Next P P Temp Free ( P ) P = Temp Temp , P = NULL
  • 19. DOUBLY LINKED LIST ◦ Doubly linked list is a linked data structure that consists of a set of sequentially linked records called nodes. ◦ Each node contains three fields ◦ one is data part which contain data only. ◦ two other field is links part that are point or references to the previous or to the next node in the sequence of nodes. ◦ The beginning and ending nodes' previous and next links, respectively, point to some kind of terminator, typically a sentinel node or null to facilitate traversal of the list. Dr. SINDHIA LINGASWAMY, VIT 19
  • 20. REPRESENTATION Dr. SINDHIA LINGASWAMY, VIT 20 20 300 1000 30 5700 300 40
  • 21. COMPARED WITH SLL ◦ Advantages ◦ Can be traversed in either direction (may be essential for some programs) ◦ Some operations, such as deletion and inserting before a node, become easier ◦ Disadvantages ◦ Requires more space ◦ List manipulations are slower (because more links must be changed) ◦ Greater chance of having bugs (because more links must be manipulated) Dr. SINDHIA LINGASWAMY, VIT 21
  • 22. INSERTION Dr. SINDHIA LINGASWAMY, VIT 22 20 30 40 H 25 L P NEW NODE
  • 23. ROUTINE – INSERTION void Insert ( int X, list L, position P ) { Struct Node *Newnode; Newnode = malloc )sizeof (Struct Node)); If ( Newnode ! = NULL ) { Newnode → Element = X; Newnode → Flink = P → Flink; P→Flink→Blink = Newnode; P→Flink = Newnode; Newnode →Blink = P; } } Dr. SINDHIA LINGASWAMY, VIT 23
  • 24. DELETION Dr. SINDHIA LINGASWAMY, VIT 24 20 30 40 H P
  • 25. ROUTINE – DELETION void Delete ( int X, List L) { position P; P = Find(X,L); if ( IsLast(P,L)) { Temp = P ; P→Blink→Flink – NULL; free (Temp); } else { Temp = P; P→Blink →Flink = P →Flink; P→Flink→Blink = P→Blink; Free (Temp); } } Dr. SINDHIA LINGASWAMY, VIT 25
  • 26. CIRCULAR LINKED LIST • The pointer of the las t node points to the first node • Can be implemented as • Singly linked circular list • Doubly linked circular list Dr. SINDHIA LINGASWAMY, VIT 26 5700 20 300 1000 30 5700 300 40 1000 10 20 30