Friday, 25 January 2013

Algorithm for Insert a node at a Position of a Linked List

ALGORITHM NAME: INSERT_BEGIN_LL(START,D)

1.start
2.Create a node and store its starting address to temp
3.if temp=NULL
                1.Print insertion is not possible
                2.Exit
4.End if
5.temp->data=d
6.temp->link=NULL
7.If p=1
                1.temp->link=start
                2.start=temp
                3.Exit
8.End if
9.If start=NULL
                1.Print Insertion is not Possible
                2.Exit
10.end if
11.c=1
12.e=start
13.while c<p-1
                1.e=e->link
                2.c=c+1
                3.If e=NULL
                                1.Print Out of Range
                                2.Exit
                4.end if
14.End while
15.temp->link=e->link
16.e->link=temp
17.stop

No comments:

Post a Comment