write an algorithm to “Insertion At specific Location”

Algorithm:

Insert (node head, value, loc)
1. [Start]
2. Node temp
Temp->data=value
Node ptr=head
3. [Repeat loop]
While (ptr!=null)
Count++
Ptr=ptr->next
[End of loop step (3)]
4. [Check condition]
If head=null AND loc=1
Head=temp
Else if (loc<count)
Ptr=head
4.1[Repeat loop]
While (loc>0)
Ptr=ptr->next
Loc–
[End of loop step (4.1)]
Temp->next=ptr->next
Ptr->next=temp
Else if loc=count+1
Ptr=head
4.2[Repeat loop]
While (ptr!=null)
Ptr=ptr->next
[End of loop step (4.2)]
Ptr->ext=temp
Else
Show “Invalid value”
[End of if else step (4)]
5. [Return]

Leave a Reply

Your email address will not be published. Required fields are marked *