SlideShare a Scribd company logo
1 of 15
Download to read offline
Creating a Linked list :
Algorithm :
Create first node and assign the address of the first node to the
pointer ‘start’.
Step : 1 start =getnode( );
Use another pointer to store the address of the first node, called
CURRPTR
Step : 2 currptr=Start;
Accept the item and store it in the INFO field of the node
Step : 3 info[currptr ]= item;
Accept the Choice from the keyboard whether to create another node
or not
Step : 4 if ( choice = ‘Y’)
goto step 5
else
goto step 6
If choice is ‘Y’ to create another node
Step : 5 i) Newnode = getnode( );
Newnode which contains the address of the newly created node
ii) link[currptr]=Newnode;
Making a link between the original last node and present newnode
iii) currptr=Newnode;
Address of the Newnode is assigned to the original newnode
iv) info[currptr]=item;
Accepting the item and storing it in the info field of currptr
go to step 4
If choice is ‘N’ to make the LINK field of the last node to NULL
Step : 6 link [currptr] = NULL and
Exit
Step : 7 return
• Traversing a linked list :
Algorithm:
Step 1 : Is linked list is empty
if ( start ==NULL)
display (“ linked list is empty “);
exit( )
Step 2 : Assign start value to CURRPTR
currptr=start;
Step 3 : Repeat while(currptr!=NULL)
Process info[currptr]
Step 4 : currptr=link[currptr] /* moving the currptr from one
node to the next node */
Step 5 : Exit
• Algorithm for Displaying a list :
• first check list is empty or not
• Step 1 : if ( start == NULL)
– Write (“ list is Empty”)
– return;
Store the Address of first node in another pointer CURRPTR
• Step 2 : set currptr = start;
• Step 3 : Repeat step4 and step5 while ( currptr !=NULL)
• Display items one-by-one from first node until Currptr becomes
NULL
• Step 4 : display ( info[currptr]);
After the display of this element ,Currptr should point to the next node
• Step 5 : currptr=link[currptr];
• Step 6 : Exit
• Insert operation at the beginning :
• Algorithm :
• Creating a node that is to be inserted
• step 1 : Newnode =getnode( );
• Enter the item into the Info field of the New node
• step 2 : info [Newnode]= item;
• Assign the start value to the LINK part of the inserted node(New
node).
• It makes a link from ‘New node’ to the previous first node.
• Now start and New node points to the original first node of the list.
• It makes link between start and Newnode.
• step 3 : link [Newnode]=start;
• step 4 : start = Newnode;
Exit;
• Algorithm : insert operation at end
Step 1 : if list is empty
if ( start == NULL)
insert at the beginning
exit( )
end if
Step 2 : currptr = start;
Traverse the list to obtain the last node address
Step 3 : while (link [currptr]! = NULL)
currptr = link [ currptr]
end while
Create a newnode and enter the accepted ITEM into its INFO fields
Step 4 : Newnode =getnode( );
Newnode -> info =item;
Make a link between Currptr(last node) and New node
Step 5 : link [currptr] = Newnode;
Step 6 : link [Newnode] = NULL
Step 7 : Exit
• Algorithm for Inserting at certain position :
Step 1: Set CURRPTR to Start
Currptr=Start
Step 2: If the item is to be inserted at 1st position
if (pos==1)
Algorithm for inserting at beginning
Else go to step 3
Step 3: If the item to inserted at some position other than 1st position
for ( i=0; i < pos-2;i++)
{
Currptr= LINK[Currptr]
}
Step 4: Create a Newnode
Newnode=getnode();
Step 5: Enter the element in the INFO field of Newnode
INFO[Newnode]=ITEM;
Step 6: Make a connection between the Newnode and the next node after
CURRPTR
LINK[Newnode]=LINK[Currptr]
Step 7: Make a link between Currptr and newnode
LINK[Currptr]=Newnode;
Step 8 : Exit
• Delete a node from the beginning:
• Algorithm:
Step 1 : check whether the list is empty
if ( start==NULL)
• write “ linked list is empty”
• else goto step 2
Step 2 : Set Currptr to start
Currptr=start;
Step 3 : Assign the link field of the first node to ‘start’ to delete the
original first node
start = link[start];
Step 4 : Free the deleted item
free(Currptr);
Step 5 : Exit
• Delete a node At the end:
• Algorithm:
Step 1 : check whether the list is empty
if ( start==NULL)
• write “ linked list is empty”
• else goto step 2
Step 2 : check if the list has only one element
if ( Link[start]==NULL) then
start=NULL;
else goto step 4
Step 3 : free the deleted node
free(start);
Step 4 : Assign start value to Currptr
Currptr=start;
Step 5 : Assign NULL to the another pointer PREVPTR
PREVPTR = NULL
Step 6 : Traverse the list until the Currptr points to last node
and PREVPTR points to the last before node
While(Link[Currptr]!=NULL)
{
PREVPTR=Currptr;
Currptr = Currptr -> link;
Step 7 : To make the LINK part of the last node, after
deletion to NULL
PREVPTR->LINK=NULL
Step 8 : Exit
• Delete a node at the given position:
• Algorithm:
→ Step 1: Check for the position whether the deletion is at first position
if ( pos==1)
Algorithm for deleting a node at beginning
else goto Step 2
→ Step 2 : Set Currptr to Start
Currptr=start
→ Step 3: set PREVPTR to NULL
PREVPTR = NULL
→Step 4 : if the item to be deleted is not at first position
for ( i=1; i<pos; i++ )
{
PREVPTR=Currptr;
Currptr = Currptr->link
}
• → Step 5 : LINK of PREVPTR is assigned with Link of
Currptr i.e. … make a link between the PREVPTR and the
next node of Currptr
PREVPTR → Link = Currptr→link
Step 6 : Exit
• Searching in a single linked list
• Algorithm :
• Step 1: set Currptr=start LOC = NULL
• Step 2: Repeat step 3 while (Currptr !=NULL)
• Step 3: if (item == Info [Currptr] )
– Then LOC = Currptr
– And display “ Search Successful “
– Exit
– else
– Currptr = Link [ Currptr ]
[ so Currptr, Now points to the next node ]
• Step 4: if LOC = NULL
Display “ Search unsuccessful “
• Step 5 : Exit
• Garbage Collection:
Garbage collection is the automatic reclamation of computer storage
The GC function is to find data objects that are no longer in use and make their
space available by the running program.
So Why Garbage Collection:
A software routine operating on data structure should not have to depend
what other routines may be operating on the same structure.
If the process does not free used memory the unused space is accumulated
until the process terminates.
Garbage collection is considered cheaper than explicit deal location
A good garbage collector shows a program down by factor of 10 percent.
Although it seems a lot , it is only a small price to pay for :
Convenience
Development time
Reliability

More Related Content

Similar to algorithms_in_linkedlist (1).pdf

Similar to algorithms_in_linkedlist (1).pdf (20)

Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & Deletion
 
Data Structure
Data StructureData Structure
Data Structure
 
Data structures linked list introduction.pptx
Data structures linked list introduction.pptxData structures linked list introduction.pptx
Data structures linked list introduction.pptx
 
Singly link list
Singly link listSingly link list
Singly link list
 
Linked list
Linked listLinked list
Linked list
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
 
Lect 11-12 Zaheer Abbas
Lect 11-12 Zaheer AbbasLect 11-12 Zaheer Abbas
Lect 11-12 Zaheer Abbas
 
Data Structures with C Linked List
Data Structures with C Linked ListData Structures with C Linked List
Data Structures with C Linked List
 
Unit 2 linked list and queues
Unit 2   linked list and queuesUnit 2   linked list and queues
Unit 2 linked list and queues
 
Stack - PPT Slides.pptx-data sturutures and algorithanms
Stack - PPT Slides.pptx-data sturutures and algorithanmsStack - PPT Slides.pptx-data sturutures and algorithanms
Stack - PPT Slides.pptx-data sturutures and algorithanms
 
Linked list
Linked listLinked list
Linked list
 
linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptx
 
queue
queuequeue
queue
 
@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
 
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
 
lecture-k-sorting.ppt
lecture-k-sorting.pptlecture-k-sorting.ppt
lecture-k-sorting.ppt
 
3.ppt
3.ppt3.ppt
3.ppt
 
Lecture k-sorting
Lecture k-sortingLecture k-sorting
Lecture k-sorting
 
linkrd_list.pdf
linkrd_list.pdflinkrd_list.pdf
linkrd_list.pdf
 

More from Koteswari Kasireddy

Chapter-7-Sampling & sampling Distributions.pdf
Chapter-7-Sampling & sampling Distributions.pdfChapter-7-Sampling & sampling Distributions.pdf
Chapter-7-Sampling & sampling Distributions.pdfKoteswari Kasireddy
 
Object_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdfObject_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdfKoteswari Kasireddy
 
Relational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptxRelational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptxKoteswari Kasireddy
 
Unit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptxUnit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptxKoteswari Kasireddy
 
Database System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptxDatabase System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptxKoteswari Kasireddy
 
Control_Statements_in_Python.pptx
Control_Statements_in_Python.pptxControl_Statements_in_Python.pptx
Control_Statements_in_Python.pptxKoteswari Kasireddy
 
parts_of_python_programming_language.pptx
parts_of_python_programming_language.pptxparts_of_python_programming_language.pptx
parts_of_python_programming_language.pptxKoteswari Kasireddy
 

More from Koteswari Kasireddy (20)

DA Syllabus outline (2).pptx
DA Syllabus outline (2).pptxDA Syllabus outline (2).pptx
DA Syllabus outline (2).pptx
 
Chapter-7-Sampling & sampling Distributions.pdf
Chapter-7-Sampling & sampling Distributions.pdfChapter-7-Sampling & sampling Distributions.pdf
Chapter-7-Sampling & sampling Distributions.pdf
 
Object_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdfObject_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdf
 
unit-3_Chapter1_RDRA.pdf
unit-3_Chapter1_RDRA.pdfunit-3_Chapter1_RDRA.pdf
unit-3_Chapter1_RDRA.pdf
 
DBMS_UNIT_1.pdf
DBMS_UNIT_1.pdfDBMS_UNIT_1.pdf
DBMS_UNIT_1.pdf
 
business analytics
business analyticsbusiness analytics
business analytics
 
Relational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptxRelational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptx
 
CHAPTER -12 it.pptx
CHAPTER -12 it.pptxCHAPTER -12 it.pptx
CHAPTER -12 it.pptx
 
WEB_DATABASE_chapter_4.pptx
WEB_DATABASE_chapter_4.pptxWEB_DATABASE_chapter_4.pptx
WEB_DATABASE_chapter_4.pptx
 
Unit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptxUnit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptx
 
Database System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptxDatabase System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptx
 
Evolution Of WEB_students.pptx
Evolution Of WEB_students.pptxEvolution Of WEB_students.pptx
Evolution Of WEB_students.pptx
 
Presentation1.pptx
Presentation1.pptxPresentation1.pptx
Presentation1.pptx
 
Algorithm.pptx
Algorithm.pptxAlgorithm.pptx
Algorithm.pptx
 
Control_Statements_in_Python.pptx
Control_Statements_in_Python.pptxControl_Statements_in_Python.pptx
Control_Statements_in_Python.pptx
 
Python_Functions_Unit1.pptx
Python_Functions_Unit1.pptxPython_Functions_Unit1.pptx
Python_Functions_Unit1.pptx
 
parts_of_python_programming_language.pptx
parts_of_python_programming_language.pptxparts_of_python_programming_language.pptx
parts_of_python_programming_language.pptx
 
linked_list.pptx
linked_list.pptxlinked_list.pptx
linked_list.pptx
 
matrices_and_loops.pptx
matrices_and_loops.pptxmatrices_and_loops.pptx
matrices_and_loops.pptx
 
algorithms_in_linkedlist.pptx
algorithms_in_linkedlist.pptxalgorithms_in_linkedlist.pptx
algorithms_in_linkedlist.pptx
 

Recently uploaded

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 

Recently uploaded (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 

algorithms_in_linkedlist (1).pdf

  • 1. Creating a Linked list : Algorithm : Create first node and assign the address of the first node to the pointer ‘start’. Step : 1 start =getnode( ); Use another pointer to store the address of the first node, called CURRPTR Step : 2 currptr=Start; Accept the item and store it in the INFO field of the node Step : 3 info[currptr ]= item; Accept the Choice from the keyboard whether to create another node or not Step : 4 if ( choice = ‘Y’) goto step 5 else goto step 6 If choice is ‘Y’ to create another node
  • 2. Step : 5 i) Newnode = getnode( ); Newnode which contains the address of the newly created node ii) link[currptr]=Newnode; Making a link between the original last node and present newnode iii) currptr=Newnode; Address of the Newnode is assigned to the original newnode iv) info[currptr]=item; Accepting the item and storing it in the info field of currptr go to step 4 If choice is ‘N’ to make the LINK field of the last node to NULL Step : 6 link [currptr] = NULL and Exit Step : 7 return
  • 3. • Traversing a linked list : Algorithm: Step 1 : Is linked list is empty if ( start ==NULL) display (“ linked list is empty “); exit( ) Step 2 : Assign start value to CURRPTR currptr=start; Step 3 : Repeat while(currptr!=NULL) Process info[currptr] Step 4 : currptr=link[currptr] /* moving the currptr from one node to the next node */ Step 5 : Exit
  • 4. • Algorithm for Displaying a list : • first check list is empty or not • Step 1 : if ( start == NULL) – Write (“ list is Empty”) – return; Store the Address of first node in another pointer CURRPTR • Step 2 : set currptr = start; • Step 3 : Repeat step4 and step5 while ( currptr !=NULL) • Display items one-by-one from first node until Currptr becomes NULL • Step 4 : display ( info[currptr]); After the display of this element ,Currptr should point to the next node • Step 5 : currptr=link[currptr]; • Step 6 : Exit
  • 5. • Insert operation at the beginning : • Algorithm : • Creating a node that is to be inserted • step 1 : Newnode =getnode( ); • Enter the item into the Info field of the New node • step 2 : info [Newnode]= item; • Assign the start value to the LINK part of the inserted node(New node). • It makes a link from ‘New node’ to the previous first node. • Now start and New node points to the original first node of the list. • It makes link between start and Newnode. • step 3 : link [Newnode]=start; • step 4 : start = Newnode; Exit;
  • 6. • Algorithm : insert operation at end Step 1 : if list is empty if ( start == NULL) insert at the beginning exit( ) end if Step 2 : currptr = start; Traverse the list to obtain the last node address Step 3 : while (link [currptr]! = NULL) currptr = link [ currptr] end while Create a newnode and enter the accepted ITEM into its INFO fields Step 4 : Newnode =getnode( ); Newnode -> info =item; Make a link between Currptr(last node) and New node Step 5 : link [currptr] = Newnode; Step 6 : link [Newnode] = NULL Step 7 : Exit
  • 7. • Algorithm for Inserting at certain position : Step 1: Set CURRPTR to Start Currptr=Start Step 2: If the item is to be inserted at 1st position if (pos==1) Algorithm for inserting at beginning Else go to step 3 Step 3: If the item to inserted at some position other than 1st position for ( i=0; i < pos-2;i++) { Currptr= LINK[Currptr] } Step 4: Create a Newnode Newnode=getnode();
  • 8. Step 5: Enter the element in the INFO field of Newnode INFO[Newnode]=ITEM; Step 6: Make a connection between the Newnode and the next node after CURRPTR LINK[Newnode]=LINK[Currptr] Step 7: Make a link between Currptr and newnode LINK[Currptr]=Newnode; Step 8 : Exit
  • 9. • Delete a node from the beginning: • Algorithm: Step 1 : check whether the list is empty if ( start==NULL) • write “ linked list is empty” • else goto step 2 Step 2 : Set Currptr to start Currptr=start; Step 3 : Assign the link field of the first node to ‘start’ to delete the original first node start = link[start]; Step 4 : Free the deleted item free(Currptr); Step 5 : Exit
  • 10. • Delete a node At the end: • Algorithm: Step 1 : check whether the list is empty if ( start==NULL) • write “ linked list is empty” • else goto step 2 Step 2 : check if the list has only one element if ( Link[start]==NULL) then start=NULL; else goto step 4 Step 3 : free the deleted node free(start); Step 4 : Assign start value to Currptr Currptr=start; Step 5 : Assign NULL to the another pointer PREVPTR PREVPTR = NULL
  • 11. Step 6 : Traverse the list until the Currptr points to last node and PREVPTR points to the last before node While(Link[Currptr]!=NULL) { PREVPTR=Currptr; Currptr = Currptr -> link; Step 7 : To make the LINK part of the last node, after deletion to NULL PREVPTR->LINK=NULL Step 8 : Exit
  • 12. • Delete a node at the given position: • Algorithm: → Step 1: Check for the position whether the deletion is at first position if ( pos==1) Algorithm for deleting a node at beginning else goto Step 2 → Step 2 : Set Currptr to Start Currptr=start → Step 3: set PREVPTR to NULL PREVPTR = NULL →Step 4 : if the item to be deleted is not at first position for ( i=1; i<pos; i++ ) { PREVPTR=Currptr; Currptr = Currptr->link }
  • 13. • → Step 5 : LINK of PREVPTR is assigned with Link of Currptr i.e. … make a link between the PREVPTR and the next node of Currptr PREVPTR → Link = Currptr→link Step 6 : Exit
  • 14. • Searching in a single linked list • Algorithm : • Step 1: set Currptr=start LOC = NULL • Step 2: Repeat step 3 while (Currptr !=NULL) • Step 3: if (item == Info [Currptr] ) – Then LOC = Currptr – And display “ Search Successful “ – Exit – else – Currptr = Link [ Currptr ] [ so Currptr, Now points to the next node ] • Step 4: if LOC = NULL Display “ Search unsuccessful “ • Step 5 : Exit
  • 15. • Garbage Collection: Garbage collection is the automatic reclamation of computer storage The GC function is to find data objects that are no longer in use and make their space available by the running program. So Why Garbage Collection: A software routine operating on data structure should not have to depend what other routines may be operating on the same structure. If the process does not free used memory the unused space is accumulated until the process terminates. Garbage collection is considered cheaper than explicit deal location A good garbage collector shows a program down by factor of 10 percent. Although it seems a lot , it is only a small price to pay for : Convenience Development time Reliability