SlideShare a Scribd company logo
1 of 15
LINKED LISTS
Mrs.V. JAYAVANI
Assistant Professor
Department of Computer Science
E.M.G. Yadava Women’s College
INTRODUCTION
• A linked list is a linear collection of data elements called
nodes in which linear representation is given by links from
one node to the next node.
• Linked list is a data structure which in turn can be used to
implement other data structures. Thus, it acts as building
block to implement data structures like stacks, queues and
their variations.
• A linked list can be perceived as a train or a sequence of
nodes in which each node contains one or more data fields
and a pointer to the next node.
SIMPLE LINKED LIST
1 2 3 4 5 6 7 X
START
• In the above linked list, every node contains two parts
- one integer and the other a pointer to the next node.
• The left part of the node which contains data may include a
simple data type, an array or a structure.
• The right part of the node contains a pointer to the next
node (or address of the next node in sequence).
• The last node will have no next node connected to it, so
it will store a special value called NULL.
TRAVERSING LINKED LISTS
• We can traverse the entire linked list using a single
pointer variable called START.
• The START node contains the address of the first node; the
next part of the first node in turn stores the address
of its succeeding node.
• Using this technique the individual nodes of the list will
form a chain of nodes.
• If START = NULL, this means that the linked list is
empty and contains no nodes.
• In C, we can implement a linked list using the following
code: struct node
{
int data;
struct node *next;
};
START Pointer
1 DATA
NEXT
H 4
E 7
L 8
L 10
O -1
1
2
3
4
5
6
7
8
9
10
START
START pointing to
the first element of
the linked list in
memory
9
AVAIL
SINGLY LINKED LISTS
• A singly linked list is the simplest type of linked list in
which every node contains some data and a pointer to
the next node of the same data type.
1 2 3 4 5 6 7 X
START
ALGORITHM FOR TRAVERSING A LINKED LIST
Step 1: [INITIALIZE] SET PTR = START
Step 2: Repeat Steps 3 and 4 while PTR != NULL
Step 3: Apply Process to PTR->DATA
Step 4: SET PTR = PTR->NEXT
[END OF LOOP]
Step 5: EXIT
SEARCHING A LINKED LIST
ALGORITHM TO SEARCH A LINKED LIST
Step 1: [INITIALIZE] SET PTR = START
Step 2: Repeat Step 3 while PTR != NULL
Step 3: IF VAL = PTR->DATA
SET POS = PTR
Go To Step 5
ELSE
SET PTR = PTR->NEXT
[END OF IF]
[END OF LOOP]
Step 4: SET POS = NULL
Step 5: EXIT
SEARCHING FOR VAL 4 IN LINKED LIST
1 7 3 4 2 6 5 X
PTR
1 7 3 4 2 6 5 X
PTR
1 7 4 2 6 5 X
3
PTR
1 7 3 4 2 6 5 X
PTR
INSERTING A NODE AT THE BEGINNING
1 7 3 4 2 6 5 X
START
START
9 1 7 3 4 2 6 5 X
ALGORITHM TO INSERT A NEW NODE IN THE BEGINNING OF THE LINKED LIST
Step 1: IF AVAIL = NULL, then
Write OVERFLOW
Go to Step 7
[END OF IF]
Step 2: SET New_Node = AVAIL
Step 3: SET AVAIL = AVAIL->NEXT
Step 4: SET New_Node->DATA = VAL
Step 5: SET New_Node->Next = START
Step 6: SET START = New_Node
Step 7: EXIT
INSERTING A NODE AT THE END
1 7 3 4 2 6 5 X
START, PTR
1 7 3 4 2 6 5 9 X
START
ALGORITHM TO INSERT A NEW NODE AT THE END OF THE LINKED LIST
Step 1: IF AVAIL = NULL, then
Write OVERFLOW
Go to Step 10
[END OF IF]
Step 2: SET New_Node = AVAIL
Step 3: SET AVAIL = AVAIL->NEXT
Step 4: SET New_Node->DATA = VAL
Step 5: SET New_Node->Next = NULL
Step 6: SET PTR = START
Step 7: Repeat Step 8 while PTR->NEXT != NULL
Step 8: SET PTR = PTR ->NEXT
[END OF LOOP]
Step 9: SET PTR->NEXT = New_Node
Step 10: EXIT
INSERTING A NODE AFTER NODE THAT
HAS VALUE NUM
ALGORITHM TO INSERT A NEW NODE AFTER A NODE THAT HAS VALUE NUM
Step 1: IF AVAIL = NULL, then
Write OVERFLOW
Go to Step 12
[END OF IF]
Step 2: SET New_Node = AVAIL
Step 3: SET AVAIL = AVAIL->NEXT
Step 4: SET New_Node->DATA = VAL
Step 5: SET PTR = START
Step 6: SET PREPTR = PTR
Step 7: Repeat Steps 8 and 9 while PREPTR->DATA != NUM
Step 8: SET PREPTR = PTR
Step 9: SET PTR = PTR->NEXT
[END OF LOOP]
Step 10: PREPTR->NEXT = New_Node
Step 11: SET New_Node->NEXT = PTR
Step 12: EXIT
DELETING THE FIRST NODE
Algorithm to delete the first node from the linked list
Step 1: IF START = NULL, then
Write UNDERFLOW
Go to Step 5
[END OF IF]
Step 2: SET PTR = START
Step 3: SET START = START->NEXT
Step 4: FREE PTR
Step 5: EXIT
1 7 3 4 2 6 5 X
7 3 4 2 6 5 X
START
START
DELETING THE LAST NODE
ALGORITHM TO DELETE THE LAST NODE OF THE LINKED LIST
Step 1: IF START = NULL, then
Write UNDERFLOW
Go to Step 8
[END OF IF]
Step 2: SET PTR = START
Step 3: Repeat Steps 4 and 5 while PTR->NEXT != NULL
Step 4: SET PREPTR = PTR
Step 5: SET PTR = PTR->NEXT
[END OF LOOP]
Step 6: SET PREPTR->NEXT = NULL
Step 7: FREE PTR
Step 8: EXIT
1 7 3 4 2 6 5 X
START, PREPTR, PTR
1 7 3 4 2 6 X 5 X
PREPTR PTR
START
DELETING THE NODE AFTER A
GIVEN NODE
ALGORITHM TO DELETE THE NODE AFTER A GIVEN NODE FROM THE LINKED LIST
Step 1: IF START = NULL, then
Write UNDERFLOW
Go to Step 10
[END OF IF]
Step 2: SET PTR = START
Step 3: SET PREPTR = PTR
Step 4: Repeat Step 5 and 6 while PRETR->DATA != NUM
Step 5: SET PREPTR = PTR
Step 6: SET PTR = PTR->NEXT
[END OF LOOP]
Step7: SET TEMP = PTR->NEXT
Step 8: SET PREPTR->NEXT = TEMP->NEXT
Step 9: FREE TEMP
Step 10: EXIT
SINGLY LINKED LIST
1 7 3 4 2 6 5 X
START, PREPTR, PTR
1 7 3 4 2 6 5 X
PREPTR PTR
START
1 7 3 4 2 6 5 X
START
1 7 3 4 6 5 X

More Related Content

Similar to Introduction Linked Lists - Singly Linked List,

4.linked list(contd.)
4.linked list(contd.)4.linked list(contd.)
4.linked list(contd.)Chandan Singh
 
Lecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsLecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsAakash deep Singhal
 
Unit 2 linked list and queues
Unit 2   linked list and queuesUnit 2   linked list and queues
Unit 2 linked list and queueskalyanineve
 
Chapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdfChapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdfAxmedcarb
 
Link list(by harshit)
Link list(by harshit)Link list(by harshit)
Link list(by harshit)Harshit Jain
 
VCE Unit 02 (1).pptx
VCE Unit 02 (1).pptxVCE Unit 02 (1).pptx
VCE Unit 02 (1).pptxskilljiolms
 
Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5Kumar
 
data structures lists operation of lists
data structures lists operation of listsdata structures lists operation of lists
data structures lists operation of listsmuskans14
 
header, circular and two way linked lists
header, circular and two way linked listsheader, circular and two way linked lists
header, circular and two way linked listsstudent
 
Linked List Presentation in data structurepptx
Linked List Presentation in data structurepptxLinked List Presentation in data structurepptx
Linked List Presentation in data structurepptxnikhilcse1
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked ListsAfaq Mansoor Khan
 

Similar to Introduction Linked Lists - Singly Linked List, (20)

4.linked list(contd.)
4.linked list(contd.)4.linked list(contd.)
4.linked list(contd.)
 
Lecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsLecture 5 data structures and algorithms
Lecture 5 data structures and algorithms
 
Unit 2 linked list and queues
Unit 2   linked list and queuesUnit 2   linked list and queues
Unit 2 linked list and queues
 
Chapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdfChapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdf
 
Link list(by harshit)
Link list(by harshit)Link list(by harshit)
Link list(by harshit)
 
DSModule2.pptx
DSModule2.pptxDSModule2.pptx
DSModule2.pptx
 
VCE Unit 02 (1).pptx
VCE Unit 02 (1).pptxVCE Unit 02 (1).pptx
VCE Unit 02 (1).pptx
 
Linked list implementation of Stack
Linked list implementation of StackLinked list implementation of Stack
Linked list implementation of Stack
 
Linklist
LinklistLinklist
Linklist
 
Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5
 
Linked List
Linked ListLinked List
Linked List
 
Linked lists a
Linked lists aLinked lists a
Linked lists a
 
data structures lists operation of lists
data structures lists operation of listsdata structures lists operation of lists
data structures lists operation of lists
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
header, circular and two way linked lists
header, circular and two way linked listsheader, circular and two way linked lists
header, circular and two way linked lists
 
Linked List Presentation in data structurepptx
Linked List Presentation in data structurepptxLinked List Presentation in data structurepptx
Linked List Presentation in data structurepptx
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
 
Singly link list
Singly link listSingly link list
Singly link list
 
Linked Lists.pdf
Linked Lists.pdfLinked Lists.pdf
Linked Lists.pdf
 
linkrd_list.pdf
linkrd_list.pdflinkrd_list.pdf
linkrd_list.pdf
 

More from JayaKamal

To learn Basic Excel - Data Entry, Formulas and Functions
To learn Basic Excel - Data Entry, Formulas and FunctionsTo learn Basic Excel - Data Entry, Formulas and Functions
To learn Basic Excel - Data Entry, Formulas and FunctionsJayaKamal
 
Introduction - Data Structures and Algorithms.ppt
Introduction - Data Structures and Algorithms.pptIntroduction - Data Structures and Algorithms.ppt
Introduction - Data Structures and Algorithms.pptJayaKamal
 
What is an Operating Systems?
What is an Operating Systems?What is an Operating Systems?
What is an Operating Systems?JayaKamal
 
Software Engineering
Software Engineering Software Engineering
Software Engineering JayaKamal
 
Software Engineering
Software Engineering Software Engineering
Software Engineering JayaKamal
 
Software Engineering
Software Engineering Software Engineering
Software Engineering JayaKamal
 
Software Engineering
Software Engineering Software Engineering
Software Engineering JayaKamal
 
Software Engineering
 Software Engineering  Software Engineering
Software Engineering JayaKamal
 
Software Engineering
 Software Engineering  Software Engineering
Software Engineering JayaKamal
 

More from JayaKamal (10)

To learn Basic Excel - Data Entry, Formulas and Functions
To learn Basic Excel - Data Entry, Formulas and FunctionsTo learn Basic Excel - Data Entry, Formulas and Functions
To learn Basic Excel - Data Entry, Formulas and Functions
 
Introduction - Data Structures and Algorithms.ppt
Introduction - Data Structures and Algorithms.pptIntroduction - Data Structures and Algorithms.ppt
Introduction - Data Structures and Algorithms.ppt
 
What is an Operating Systems?
What is an Operating Systems?What is an Operating Systems?
What is an Operating Systems?
 
Jsp
JspJsp
Jsp
 
Software Engineering
Software Engineering Software Engineering
Software Engineering
 
Software Engineering
Software Engineering Software Engineering
Software Engineering
 
Software Engineering
Software Engineering Software Engineering
Software Engineering
 
Software Engineering
Software Engineering Software Engineering
Software Engineering
 
Software Engineering
 Software Engineering  Software Engineering
Software Engineering
 
Software Engineering
 Software Engineering  Software Engineering
Software Engineering
 

Recently uploaded

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Recently uploaded (20)

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 

Introduction Linked Lists - Singly Linked List,

  • 1. LINKED LISTS Mrs.V. JAYAVANI Assistant Professor Department of Computer Science E.M.G. Yadava Women’s College
  • 2. INTRODUCTION • A linked list is a linear collection of data elements called nodes in which linear representation is given by links from one node to the next node. • Linked list is a data structure which in turn can be used to implement other data structures. Thus, it acts as building block to implement data structures like stacks, queues and their variations. • A linked list can be perceived as a train or a sequence of nodes in which each node contains one or more data fields and a pointer to the next node.
  • 3. SIMPLE LINKED LIST 1 2 3 4 5 6 7 X START • In the above linked list, every node contains two parts - one integer and the other a pointer to the next node. • The left part of the node which contains data may include a simple data type, an array or a structure. • The right part of the node contains a pointer to the next node (or address of the next node in sequence). • The last node will have no next node connected to it, so it will store a special value called NULL.
  • 4. TRAVERSING LINKED LISTS • We can traverse the entire linked list using a single pointer variable called START. • The START node contains the address of the first node; the next part of the first node in turn stores the address of its succeeding node. • Using this technique the individual nodes of the list will form a chain of nodes. • If START = NULL, this means that the linked list is empty and contains no nodes. • In C, we can implement a linked list using the following code: struct node { int data; struct node *next; };
  • 5. START Pointer 1 DATA NEXT H 4 E 7 L 8 L 10 O -1 1 2 3 4 5 6 7 8 9 10 START START pointing to the first element of the linked list in memory 9 AVAIL
  • 6. SINGLY LINKED LISTS • A singly linked list is the simplest type of linked list in which every node contains some data and a pointer to the next node of the same data type. 1 2 3 4 5 6 7 X START ALGORITHM FOR TRAVERSING A LINKED LIST Step 1: [INITIALIZE] SET PTR = START Step 2: Repeat Steps 3 and 4 while PTR != NULL Step 3: Apply Process to PTR->DATA Step 4: SET PTR = PTR->NEXT [END OF LOOP] Step 5: EXIT
  • 7. SEARCHING A LINKED LIST ALGORITHM TO SEARCH A LINKED LIST Step 1: [INITIALIZE] SET PTR = START Step 2: Repeat Step 3 while PTR != NULL Step 3: IF VAL = PTR->DATA SET POS = PTR Go To Step 5 ELSE SET PTR = PTR->NEXT [END OF IF] [END OF LOOP] Step 4: SET POS = NULL Step 5: EXIT
  • 8. SEARCHING FOR VAL 4 IN LINKED LIST 1 7 3 4 2 6 5 X PTR 1 7 3 4 2 6 5 X PTR 1 7 4 2 6 5 X 3 PTR 1 7 3 4 2 6 5 X PTR
  • 9. INSERTING A NODE AT THE BEGINNING 1 7 3 4 2 6 5 X START START 9 1 7 3 4 2 6 5 X ALGORITHM TO INSERT A NEW NODE IN THE BEGINNING OF THE LINKED LIST Step 1: IF AVAIL = NULL, then Write OVERFLOW Go to Step 7 [END OF IF] Step 2: SET New_Node = AVAIL Step 3: SET AVAIL = AVAIL->NEXT Step 4: SET New_Node->DATA = VAL Step 5: SET New_Node->Next = START Step 6: SET START = New_Node Step 7: EXIT
  • 10. INSERTING A NODE AT THE END 1 7 3 4 2 6 5 X START, PTR 1 7 3 4 2 6 5 9 X START ALGORITHM TO INSERT A NEW NODE AT THE END OF THE LINKED LIST Step 1: IF AVAIL = NULL, then Write OVERFLOW Go to Step 10 [END OF IF] Step 2: SET New_Node = AVAIL Step 3: SET AVAIL = AVAIL->NEXT Step 4: SET New_Node->DATA = VAL Step 5: SET New_Node->Next = NULL Step 6: SET PTR = START Step 7: Repeat Step 8 while PTR->NEXT != NULL Step 8: SET PTR = PTR ->NEXT [END OF LOOP] Step 9: SET PTR->NEXT = New_Node Step 10: EXIT
  • 11. INSERTING A NODE AFTER NODE THAT HAS VALUE NUM ALGORITHM TO INSERT A NEW NODE AFTER A NODE THAT HAS VALUE NUM Step 1: IF AVAIL = NULL, then Write OVERFLOW Go to Step 12 [END OF IF] Step 2: SET New_Node = AVAIL Step 3: SET AVAIL = AVAIL->NEXT Step 4: SET New_Node->DATA = VAL Step 5: SET PTR = START Step 6: SET PREPTR = PTR Step 7: Repeat Steps 8 and 9 while PREPTR->DATA != NUM Step 8: SET PREPTR = PTR Step 9: SET PTR = PTR->NEXT [END OF LOOP] Step 10: PREPTR->NEXT = New_Node Step 11: SET New_Node->NEXT = PTR Step 12: EXIT
  • 12. DELETING THE FIRST NODE Algorithm to delete the first node from the linked list Step 1: IF START = NULL, then Write UNDERFLOW Go to Step 5 [END OF IF] Step 2: SET PTR = START Step 3: SET START = START->NEXT Step 4: FREE PTR Step 5: EXIT 1 7 3 4 2 6 5 X 7 3 4 2 6 5 X START START
  • 13. DELETING THE LAST NODE ALGORITHM TO DELETE THE LAST NODE OF THE LINKED LIST Step 1: IF START = NULL, then Write UNDERFLOW Go to Step 8 [END OF IF] Step 2: SET PTR = START Step 3: Repeat Steps 4 and 5 while PTR->NEXT != NULL Step 4: SET PREPTR = PTR Step 5: SET PTR = PTR->NEXT [END OF LOOP] Step 6: SET PREPTR->NEXT = NULL Step 7: FREE PTR Step 8: EXIT 1 7 3 4 2 6 5 X START, PREPTR, PTR 1 7 3 4 2 6 X 5 X PREPTR PTR START
  • 14. DELETING THE NODE AFTER A GIVEN NODE ALGORITHM TO DELETE THE NODE AFTER A GIVEN NODE FROM THE LINKED LIST Step 1: IF START = NULL, then Write UNDERFLOW Go to Step 10 [END OF IF] Step 2: SET PTR = START Step 3: SET PREPTR = PTR Step 4: Repeat Step 5 and 6 while PRETR->DATA != NUM Step 5: SET PREPTR = PTR Step 6: SET PTR = PTR->NEXT [END OF LOOP] Step7: SET TEMP = PTR->NEXT Step 8: SET PREPTR->NEXT = TEMP->NEXT Step 9: FREE TEMP Step 10: EXIT
  • 15. SINGLY LINKED LIST 1 7 3 4 2 6 5 X START, PREPTR, PTR 1 7 3 4 2 6 5 X PREPTR PTR START 1 7 3 4 2 6 5 X START 1 7 3 4 6 5 X