SLL ALGORITHM
SLL ALGORITHM
INSERTBEGIN() :
1.create a newnode
1
2. if(newnode==NULL)
2.1. print “Out of memory space “.
3. get the value for the newnode data.
4. newnode next NULL.
5.if (head==NULL) else goto step 6
5.1. head newnode
6.else
6.1. newnode next head
6.2. head newnode.
7.call the display function.
INSERTEND() :
1.create a newnode.
2. if(newnode==NULL)
2.1. print “Out of memory space “.
3. get the value for the newnode data.
4. newnode next NULL.
5.if (head==NULL) else goto step 6
5.1. head newnode
6.else
6.1. ptrhead.
6.2. if (ptr next !=NULL).
6.2.1. ptr ptr next.
6.3. ptr next newnode.
7.call the display function.
INSERTPOSITION():
1.Declare i , pos.
2.create memory for newnode
3. if (newnode==NULL)
3.1. print “Out of memory space”
4. Read the position value
5. read the newnode data
6. initialize i=0
7. if ( ptr newnode)
7.1.ptr ptr next
7.2. if (ptr==NULL)
7.2.1. print “position not found”
7.3. newnodenext ptr next
7.4. ptr next newnode
8. call display function.
DELETBEGIN ():
1.if(head==NULL) else go to step 2
1.1.print “List is empty”
2.else
2.1.ptrhead
2.2. head head next
2.3. print deleted element
2.4. free(ptr)
2
3.call the display function
DELETEND ():
1.if(head==NULL) else go to step 2
1.1.print “List is empty”
2.else if (headnextNULL) else go to step 3
2.1. ptr head
2.2. head NULL
2.3. print deleted element
2.4. free(ptr)
3. else
3.1. ptrhead
3.2.if ( ptrnext!=NULL)
3.2.1. tempptr
3.2.2.ptr ptr next
4.tempnextNULL
5. print deleted element
6. free(ptr)
7. call display function
DELETPOSITION():
1. Declare element
2.if (head==NULL) else go to step 3
2.1. print “List is empty”
3.else
3.1. Read element
3.2. ptrfindprevious(element)
3.3. temp ptr next
3.4. ptrnext temp next
3.5. print deleted element
3.6. free (temp)
4.call display function
SEARCH ():
1.ptr head
2. if (ptr!=NULL && ptrdata!=element) else go to step 3
2.1. ptr ptr next
3. if (ptr !=NULL) else go to step 4
3.1. print “element found”
3.2 print search element
4. else
4.1 print “element not found”