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
 
Algo>ADT list & linked list
Algo>ADT list & linked listAlgo>ADT list & linked list
Algo>ADT list & linked list
Ain-ul-Moiz Khawaja
 
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
 
List
ListList
List
Amit Vats
 
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
 
Team 9
Team 9Team 9
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

Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
Mahmoud Morsy
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
Welding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdfWelding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdf
AjmalKhan50578
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
gowrishankartb2005
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
TaghreedAltamimi
 
Data Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptxData Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptx
ramrag33
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
21UME003TUSHARDEB
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
Applications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdfApplications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdf
Atif Razi
 
Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...
bijceesjournal
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
Gino153088
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
UReason
 
People as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimalaPeople as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimala
riddhimaagrawal986
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
Nada Hikmah
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
ecqow
 
integral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdfintegral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdf
gaafergoudaay7aga
 

Recently uploaded (20)

Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
Welding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdfWelding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdf
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
 
Data Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptxData Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptx
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
Applications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdfApplications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdf
 
Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
 
People as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimalaPeople as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimala
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
 
integral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdfintegral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdf
 

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