SlideShare a Scribd company logo
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

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
Estiak Khan
 
Unit - 2.pdf
Unit - 2.pdfUnit - 2.pdf
Unit - 2.pdf
AravindAnand21
 
Circular_Linked_List.ppt
Circular_Linked_List.pptCircular_Linked_List.ppt
Circular_Linked_List.ppt
SLekshmiNair
 
Linked list and its operations - Traversal
Linked list and its operations - TraversalLinked list and its operations - Traversal
Linked list and its operations - Traversal
kasthurimukila
 
Data structures & algorithms lecture 3
Data structures & algorithms lecture 3Data structures & algorithms lecture 3
Data structures & algorithms lecture 3
Poojith Chowdhary
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
Durga Devi
 
Singly Linked List
Singly Linked ListSingly Linked List
Singly Linked List
raghavbirla63
 
csc211_lecture_21.pptx
csc211_lecture_21.pptxcsc211_lecture_21.pptx
csc211_lecture_21.pptx
ASADAHMAD811380
 
LINKED LIST.pptx
LINKED LIST.pptxLINKED LIST.pptx
LINKED LIST.pptx
ManojUniversity
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
KylaMaeGarcia1
 
Linked lists
Linked listsLinked lists
Linked lists
SARITHA REDDY
 
Array linked list.ppt
Array  linked list.pptArray  linked list.ppt
Array linked list.ppt
Waf1231
 
linked-list.ppt
linked-list.pptlinked-list.ppt
linked-list.ppt
DikkySuryadiSKomMKom
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
ManishPrajapati78
 
Linked List
Linked ListLinked List
Linked List
Keshav Vaswani
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
Sumathi Kv
 
Linked list
Linked list Linked list
Linked list
Arbind Mandal
 

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

HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
Amil baba
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
shape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptxshape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptx
VishalDeshpande27
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Hall booking system project report .pdf
Hall booking system project report  .pdfHall booking system project report  .pdf
Hall booking system project report .pdf
Kamal Acharya
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
abh.arya
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdf
Kamal Acharya
 
Toll tax management system project report..pdf
Toll tax management system project report..pdfToll tax management system project report..pdf
Toll tax management system project report..pdf
Kamal Acharya
 
A case study of cinema management system project report..pdf
A case study of cinema management system project report..pdfA case study of cinema management system project report..pdf
A case study of cinema management system project report..pdf
Kamal Acharya
 
Danfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdfDanfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdf
NurvisNavarroSanchez
 
Construction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxConstruction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptx
wendy cai
 
fundamentals of drawing and isometric and orthographic projection
fundamentals of drawing and isometric and orthographic projectionfundamentals of drawing and isometric and orthographic projection
fundamentals of drawing and isometric and orthographic projection
jeevanprasad8
 
Online blood donation management system project.pdf
Online blood donation management system project.pdfOnline blood donation management system project.pdf
Online blood donation management system project.pdf
Kamal Acharya
 
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES  INTRODUCTION UNIT-IENERGY STORAGE DEVICES  INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
VigneshvaranMech
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 

Recently uploaded (20)

HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
shape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptxshape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptx
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Hall booking system project report .pdf
Hall booking system project report  .pdfHall booking system project report  .pdf
Hall booking system project report .pdf
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdf
 
Toll tax management system project report..pdf
Toll tax management system project report..pdfToll tax management system project report..pdf
Toll tax management system project report..pdf
 
A case study of cinema management system project report..pdf
A case study of cinema management system project report..pdfA case study of cinema management system project report..pdf
A case study of cinema management system project report..pdf
 
Danfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdfDanfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdf
 
Construction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxConstruction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptx
 
fundamentals of drawing and isometric and orthographic projection
fundamentals of drawing and isometric and orthographic projectionfundamentals of drawing and isometric and orthographic projection
fundamentals of drawing and isometric and orthographic projection
 
Online blood donation management system project.pdf
Online blood donation management system project.pdfOnline blood donation management system project.pdf
Online blood donation management system project.pdf
 
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES  INTRODUCTION UNIT-IENERGY STORAGE DEVICES  INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 

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