SlideShare une entreprise Scribd logo
1  sur  25
Linked List
VARIOUS TYPES OF LINKED LIST
able of Contents
 Circular Linked List
 Linked Implementation of Stack
 Linked Implementation of Queue
Application of Linked List
Concept of Linked List
 Linked list is a linear data structure.
 A Linked List is a set of nodes where each node has two fields ‘data’
and ‘link’.
DATA LINK
 Piece of Information
Data Type : Int,char,float etc.
Used to point to next node
C Representation of Simple Linked List
 C structure for creating a node in a Linked List :
typedef struct node
{
int data;
struct node *next;
}NODE;
Stores Information part of data
Stores address of next node
Circular Linked List
 Circular linked list is a sequence of elements in which every element
has link to its next element in the sequence and the last element has
the link to the first element in the sequence.
 The circular linked list is as shown below :
10 20 30 40 50
Head Node
Operation performed on Circular Linked List
 The following operation can be performed on Circular linked list.
1. Insertion
2. Deletion
3. Display
Insertion of Circular Linked list
 Algorithm:
Step 1: Create a new_node with a given value.
Step 2: Check whether list is empty (head==NULL).
Step 3: If empty, then head=new_node and new_node→next=head.
Step 4: If not empty then create a temp node pointer and initialize with
‘head’.
Step 5: Move temp node to its next node, until head node not achieved
(temp→next==head).
Step 6: Set new_node→next=head, head=new_node and
temp→next=head.
Inserting a node as a head node
 Algorithm:
Step 1: Create a new_node with a given value.
Step 2: Check whether list is empty (head==NULL).
Step 3: If empty, then head=new_node and new_node→next=head.
Step 4: If not empty then create a temp node pointer and initialize with
‘head’.
Step 5: Move temp node to its next node, until head node not achieved
(temp->next==head).
Step 6: Set temp→next=new_node and new_node→next=head.
Inserting a node as a last node
 Algorithm:
Step 1: Create a new_node with a given value.
Step 2: Check whether list is empty (head==NULL).
Step 3: If empty, then head=new_node and new_node->next=head.
Step 4: If not empty then create a temp node pointer and initialize with
‘head’.
Step 5: Define key value after which the node is to be inserted.
Step 6: Check for key value (temp→data==key).
Step 7: Every time check whether temp is reached to the last node or
not. If yes then print Node not found.
Step 8: If temp=key then check whether it is last node
(temp→next==head).
Step 9: If temp is last node then temp->next=new_node and
new_node→next=head.
Step 10: If temp is not last node then new_node→next=temp→next and
temp→next=new_node.
Inserting a node at specific location
Deletion of any node
 Algorithm:
Step 1: Check whether list is Empty (head == NULL).
Step 2: If it is Empty then, print list is empty.
Step 3: If it is Not Empty then, define two Node pointers 'temp1' and
'temp2' and initialize 'temp1' with head.
Step 4: Keep moving the temp1 until it reaches to the specified or to the
last node. And every time set 'temp2 = temp1' before moving the
'temp1' to its next node.
Step 5: If it is reached to the last node then display Node not found.
Step 6: If it is reached to the exact node which we want to delete, then
check whether list is having only one node (temp1→next == head).
Step 7: If list has only one node and that is the node to be deleted then
set head=NULL and delete temp1 (free(temp1)).
Step 8: If list contains multiple nodes then check whether temp1 is the
first node in the list (temp1 == head).
Step 9: If temp1 is the first node then set temp2 = head and keep
moving temp2 to its next node until temp2 reaches to the last node.
Then set head=head→next, temp2→next=head and delete temp1.
Step 10: If temp1 is not first node then check whether it is last node in
the list (temp1→next == head).
Step 11: If temp1 is last node then set temp2→next=head and delete
temp1 (free(temp1)).
Step 12: If temp1 is not first node and not last node then set
temp2→next = temp1→next and delete temp1 (free(temp1)).
Display Circular Linked List
 Algorithm:
Step 1: Check whether list is Empty (head == NULL).
Step 2: If it is Empty, then print list is empty.
Step 3: If it is Not Empty then, define a Node pointer 'temp' and
initialize with head.
Step 4: Keep displaying temp→data with an arrow (--->) until temp
reaches to the last node.
Step 5: Finally display temp→data with arrow pointing to head→data.
Advantages of Circular Linked list over Singly Linked
list
 In Circular linked list, the next pointer of last node in pointing to the
head node.
 Hence we can move from last node to the head node of the list very
efficiently.
 So, accessing of any node is much faster then singly linked list.
 The last node’s next pointer have null value in singly linked list while
in circular linked list it is having the address of the head node.
 Hence there is no loss of memory.
Linked Implementation of Stack
 Stack is a special case of list and therefore we can represent stack
using arrays as well as using linked list.
 The advantage of implementing stack using linked list is that we
need not have to worry about the size of the stack.
 Since we are using linked list as stack, we are inserting the nodes in
the stack and the size is dynamically changed. So there is not stack
full (Overflow condition).
C structure of Linked
Stack
Representation of Linked
Stack
struct stack
{
int data;
struct stack *next;
}NODE;
40
30
20
10 NULL
Top Node
Insert a node into Linked Stack
 We can insert the node using user defined function named
push(value).
 Algorithm:
 Step 1: Create a new_node with given value.
 Step 2: Check whether stack is Empty (top == NULL).
 Step 3: If it is Empty, then set new_node→next=NULL.
 Step 4: If it is Not Empty, then set new_node→next=top.
 Step 5: set top = new_node.
Delete a node from Linked Stack
 We can delete a node from linked stack using user defined function
called pop().
 Algorithm:
 Step 1: Check whether stack is Empty (top == NULL).
 Step 2: If it is Empty, then display “Stack is empty”.
 Step 3: If it is Not Empty, then define a Node pointer 'temp' and set it
to 'top'.
 Step 4: Then set 'top = top → next'.
 Step 5: Delete 'temp' (free(temp)).
Display Linked Stack
 Algorithm:
 Step 1: Check whether stack is Empty (top == NULL).
 Step 2: If it is Empty, then display “Stack is Empty”.
 Step 3: If it is Not Empty, then define a Node pointer 'temp' and
initialize with top.
 Step 4: Display 'temp → data --->' and move it to the next node.
Repeat the same until temp reaches to the first node in the stack
(temp → next != NULL).
 Step 5: Display 'temp → data ---> NULL'.
Linked Implementation of Queue
 We can implement queue using linked list.
 The main advantage is we need not have to worry about size of the
queue, so there will not be a queue full condition.
 The left most pointer is called front node and the right most pointer is
called rear node.
 We can not remove any arbitrary node from queue.
C structure of Linked
Queue
Representation of Linked
Queue
struct node
{
int data;
struct stack *next;
}Q;
40302010
Front
node
Rear
node
Insert a node into Linked Queue
 Algorithm:
 Step 1: Create a new_node and set new_node → next = NULL.
 Step 2: Check whether queue is Empty (rear == NULL)
 Step 3: If it is Empty then, set front = new_node and rear =
new_node.
 Step 4: If it is Not Empty then, set rear→next = new_node and rear =
new_node.
Delete a node from Linked Queue
 Algorithm:
 Step 1: Check whether queue is Empty (front == NULL).
 Step 2: If it is Empty, then display "Queue is Empty!!!”
 Step 3: If it is Not Empty then, define a Node pointer temp and set it
to front.
 Step 4: Then 'front = front → next' and delete 'temp' (free(temp)).
Display Linked Queue
 Algorithm:
 Step 1: Check whether queue is Empty (front == NULL).
 Step 2: If it is Empty then, display “Queue is Empty!!!”
 Step 3: If it is Not Empty then, define a Node pointer temp and
initialize with front.
 Step 4: Display temp → data ---> and move it to the next node.
Repeat the same until temp reaches to 'rear' (temp → next != NULL).
 Step 5: Display temp → data ---> NULL.
Application of Linked List
 Various application of linked list are :
1. Representation of polynomial and performing various operations
such as addition, multiplication and evaluation on it.
2. Performing addition of long positive integers.
3. Representing non integer and non homogeneous list.
Linked list

Contenu connexe

Tendances

Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]Muhammad Hammad Waseem
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueBalwant Gorad
 
358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10sumitbardhan
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structureMAHALAKSHMI P
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked ListNinad Mankar
 
Binary search tree
Binary search treeBinary search tree
Binary search treeKousalya M
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structuresDurgaDeviCbit
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stackvaibhav2910
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data StructureRabin BK
 

Tendances (20)

Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
Expression trees
Expression treesExpression trees
Expression trees
 
Binary tree traversal ppt - 02.03.2020
Binary tree traversal   ppt - 02.03.2020Binary tree traversal   ppt - 02.03.2020
Binary tree traversal ppt - 02.03.2020
 
Linked list
Linked listLinked list
Linked list
 
Trees
TreesTrees
Trees
 
358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
 
Linked list
Linked listLinked list
Linked list
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Link list
Link listLink list
Link list
 
Binary search tree
Binary search treeBinary search tree
Binary search tree
 
Link_List.pptx
Link_List.pptxLink_List.pptx
Link_List.pptx
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
 
Linked lists
Linked listsLinked lists
Linked lists
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
 

Similaire à Linked list

Similaire à Linked list (20)

queue
queuequeue
queue
 
Circular linked list
Circular linked list Circular linked list
Circular linked list
 
lab stack and queue.docx
lab stack and queue.docxlab stack and queue.docx
lab stack and queue.docx
 
Linked lists in Data Structure
Linked lists in Data StructureLinked lists in Data Structure
Linked lists in Data Structure
 
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssssDSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queue
 
linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptx
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
Mi 103 linked list
Mi 103 linked listMi 103 linked list
Mi 103 linked list
 
Dounly linked list
Dounly linked listDounly linked list
Dounly linked list
 
Singly linked list
Singly linked listSingly linked list
Singly linked list
 
VCE Unit 02 (1).pptx
VCE Unit 02 (1).pptxVCE Unit 02 (1).pptx
VCE Unit 02 (1).pptx
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
DSModule2.pptx
DSModule2.pptxDSModule2.pptx
DSModule2.pptx
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
 
DSA- Unit III- STACK AND QUEUE
DSA- Unit III- STACK AND QUEUEDSA- Unit III- STACK AND QUEUE
DSA- Unit III- STACK AND QUEUE
 
Stack
StackStack
Stack
 
1. 3 singly linked list insertion 2
1. 3 singly linked list   insertion 21. 3 singly linked list   insertion 2
1. 3 singly linked list insertion 2
 
Linked list implementation of Stack
Linked list implementation of StackLinked list implementation of Stack
Linked list implementation of Stack
 

Dernier

UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 

Dernier (20)

UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 

Linked list

  • 2. VARIOUS TYPES OF LINKED LIST able of Contents  Circular Linked List  Linked Implementation of Stack  Linked Implementation of Queue Application of Linked List
  • 3. Concept of Linked List  Linked list is a linear data structure.  A Linked List is a set of nodes where each node has two fields ‘data’ and ‘link’. DATA LINK  Piece of Information Data Type : Int,char,float etc. Used to point to next node
  • 4. C Representation of Simple Linked List  C structure for creating a node in a Linked List : typedef struct node { int data; struct node *next; }NODE; Stores Information part of data Stores address of next node
  • 5. Circular Linked List  Circular linked list is a sequence of elements in which every element has link to its next element in the sequence and the last element has the link to the first element in the sequence.  The circular linked list is as shown below : 10 20 30 40 50 Head Node
  • 6. Operation performed on Circular Linked List  The following operation can be performed on Circular linked list. 1. Insertion 2. Deletion 3. Display
  • 7. Insertion of Circular Linked list  Algorithm: Step 1: Create a new_node with a given value. Step 2: Check whether list is empty (head==NULL). Step 3: If empty, then head=new_node and new_node→next=head. Step 4: If not empty then create a temp node pointer and initialize with ‘head’. Step 5: Move temp node to its next node, until head node not achieved (temp→next==head). Step 6: Set new_node→next=head, head=new_node and temp→next=head. Inserting a node as a head node
  • 8.  Algorithm: Step 1: Create a new_node with a given value. Step 2: Check whether list is empty (head==NULL). Step 3: If empty, then head=new_node and new_node→next=head. Step 4: If not empty then create a temp node pointer and initialize with ‘head’. Step 5: Move temp node to its next node, until head node not achieved (temp->next==head). Step 6: Set temp→next=new_node and new_node→next=head. Inserting a node as a last node
  • 9.  Algorithm: Step 1: Create a new_node with a given value. Step 2: Check whether list is empty (head==NULL). Step 3: If empty, then head=new_node and new_node->next=head. Step 4: If not empty then create a temp node pointer and initialize with ‘head’. Step 5: Define key value after which the node is to be inserted. Step 6: Check for key value (temp→data==key). Step 7: Every time check whether temp is reached to the last node or not. If yes then print Node not found. Step 8: If temp=key then check whether it is last node (temp→next==head). Step 9: If temp is last node then temp->next=new_node and new_node→next=head. Step 10: If temp is not last node then new_node→next=temp→next and temp→next=new_node. Inserting a node at specific location
  • 10. Deletion of any node  Algorithm: Step 1: Check whether list is Empty (head == NULL). Step 2: If it is Empty then, print list is empty. Step 3: If it is Not Empty then, define two Node pointers 'temp1' and 'temp2' and initialize 'temp1' with head. Step 4: Keep moving the temp1 until it reaches to the specified or to the last node. And every time set 'temp2 = temp1' before moving the 'temp1' to its next node. Step 5: If it is reached to the last node then display Node not found. Step 6: If it is reached to the exact node which we want to delete, then check whether list is having only one node (temp1→next == head).
  • 11. Step 7: If list has only one node and that is the node to be deleted then set head=NULL and delete temp1 (free(temp1)). Step 8: If list contains multiple nodes then check whether temp1 is the first node in the list (temp1 == head). Step 9: If temp1 is the first node then set temp2 = head and keep moving temp2 to its next node until temp2 reaches to the last node. Then set head=head→next, temp2→next=head and delete temp1. Step 10: If temp1 is not first node then check whether it is last node in the list (temp1→next == head). Step 11: If temp1 is last node then set temp2→next=head and delete temp1 (free(temp1)). Step 12: If temp1 is not first node and not last node then set temp2→next = temp1→next and delete temp1 (free(temp1)).
  • 12. Display Circular Linked List  Algorithm: Step 1: Check whether list is Empty (head == NULL). Step 2: If it is Empty, then print list is empty. Step 3: If it is Not Empty then, define a Node pointer 'temp' and initialize with head. Step 4: Keep displaying temp→data with an arrow (--->) until temp reaches to the last node. Step 5: Finally display temp→data with arrow pointing to head→data.
  • 13. Advantages of Circular Linked list over Singly Linked list  In Circular linked list, the next pointer of last node in pointing to the head node.  Hence we can move from last node to the head node of the list very efficiently.  So, accessing of any node is much faster then singly linked list.  The last node’s next pointer have null value in singly linked list while in circular linked list it is having the address of the head node.  Hence there is no loss of memory.
  • 14. Linked Implementation of Stack  Stack is a special case of list and therefore we can represent stack using arrays as well as using linked list.  The advantage of implementing stack using linked list is that we need not have to worry about the size of the stack.  Since we are using linked list as stack, we are inserting the nodes in the stack and the size is dynamically changed. So there is not stack full (Overflow condition).
  • 15. C structure of Linked Stack Representation of Linked Stack struct stack { int data; struct stack *next; }NODE; 40 30 20 10 NULL Top Node
  • 16. Insert a node into Linked Stack  We can insert the node using user defined function named push(value).  Algorithm:  Step 1: Create a new_node with given value.  Step 2: Check whether stack is Empty (top == NULL).  Step 3: If it is Empty, then set new_node→next=NULL.  Step 4: If it is Not Empty, then set new_node→next=top.  Step 5: set top = new_node.
  • 17. Delete a node from Linked Stack  We can delete a node from linked stack using user defined function called pop().  Algorithm:  Step 1: Check whether stack is Empty (top == NULL).  Step 2: If it is Empty, then display “Stack is empty”.  Step 3: If it is Not Empty, then define a Node pointer 'temp' and set it to 'top'.  Step 4: Then set 'top = top → next'.  Step 5: Delete 'temp' (free(temp)).
  • 18. Display Linked Stack  Algorithm:  Step 1: Check whether stack is Empty (top == NULL).  Step 2: If it is Empty, then display “Stack is Empty”.  Step 3: If it is Not Empty, then define a Node pointer 'temp' and initialize with top.  Step 4: Display 'temp → data --->' and move it to the next node. Repeat the same until temp reaches to the first node in the stack (temp → next != NULL).  Step 5: Display 'temp → data ---> NULL'.
  • 19. Linked Implementation of Queue  We can implement queue using linked list.  The main advantage is we need not have to worry about size of the queue, so there will not be a queue full condition.  The left most pointer is called front node and the right most pointer is called rear node.  We can not remove any arbitrary node from queue.
  • 20. C structure of Linked Queue Representation of Linked Queue struct node { int data; struct stack *next; }Q; 40302010 Front node Rear node
  • 21. Insert a node into Linked Queue  Algorithm:  Step 1: Create a new_node and set new_node → next = NULL.  Step 2: Check whether queue is Empty (rear == NULL)  Step 3: If it is Empty then, set front = new_node and rear = new_node.  Step 4: If it is Not Empty then, set rear→next = new_node and rear = new_node.
  • 22. Delete a node from Linked Queue  Algorithm:  Step 1: Check whether queue is Empty (front == NULL).  Step 2: If it is Empty, then display "Queue is Empty!!!”  Step 3: If it is Not Empty then, define a Node pointer temp and set it to front.  Step 4: Then 'front = front → next' and delete 'temp' (free(temp)).
  • 23. Display Linked Queue  Algorithm:  Step 1: Check whether queue is Empty (front == NULL).  Step 2: If it is Empty then, display “Queue is Empty!!!”  Step 3: If it is Not Empty then, define a Node pointer temp and initialize with front.  Step 4: Display temp → data ---> and move it to the next node. Repeat the same until temp reaches to 'rear' (temp → next != NULL).  Step 5: Display temp → data ---> NULL.
  • 24. Application of Linked List  Various application of linked list are : 1. Representation of polynomial and performing various operations such as addition, multiplication and evaluation on it. 2. Performing addition of long positive integers. 3. Representing non integer and non homogeneous list.