Algorithm for deleting data in singly linked list






Algorithm:



Step1: Start

Step2: Read the case in ch and data

Step3: Switch n

        Case1, perform deletefront function
          
        Case2, perform deleteend function
           
        Case3,perform deleteany function

        Case4, exit

Step4: deletefront function

       1.ptr=header
       2.if ptr=null, then print list is empty
       3.else
           header=link[ptr]
           free(ptr)
      
       deleteend function
   
       1.ptr=header
       2.if ptr=null, then print list is empty
       3.find the last node and set
           link[ptr1]=null
           free(ptr)

       deleteany function

       1.read the data to be deleted
       2.if ptr=null, then print list is empty
       3.else
          find the data position and set
          link[ptr1]=link[ptr]
          free(ptr)

Step5: stop



Comments

Popular posts from this blog

Node.js Cheat Sheet

Codeigniter ! Simple But Powerful

Enhancing Supply Chain Security and Cloud-Native Development with Chainguard