[go: up one dir, main page]

0% found this document useful (0 votes)
3 views3 pages

SLL ALGORITHM

SLL Algorithm

Uploaded by

lavanya a
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

SLL ALGORITHM

SLL Algorithm

Uploaded by

lavanya a
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

SINGLE LINKED LIST ALGORITHM

1.Start the program.


2.Declare the function such as create, display ,insertbegin , insertend ,
insertposition , deletbegin ,deletend ,deletposition , Search.
3.Create a structure of struct node.
3.1. Declare data ,next, temp, ptr, newnode. head NULL
4. Read choice Create a switch case.
4.1. Get choice 1 perform create operation
4.2. Get choice 2 perform display operation
4.3. Get choice 3 perform insert begin operation
4.4. Get choice 4 perform insert end operation
4.5. Get choice 5 perform insert position operation
4.6. Get choice 6 perform delete begin operation
4.7. Get choice 7 perform delete end operation
4.8. Get choice 8 perform delete position operation
4.9. Get choice 9 perform search operation
5. Repeat the step 4 until (choice<=9)
6. End of the program
CREATE():
1.Declare i , n , newnode ;
2. Read n value.
3. initialize i0
4. if i<n
4.1. create memory for newnode
4.2. if (newnode==NULL)
4.2.1. print “Out of memory space”.
4.3. read the newnode data.
4.4. newnode nextNULL
4.5. if (head==NULL) else goto step:4.6
4.5.1. headnewnode.
4.6. else
4.6.1. ptr  head.
4.6.2. if (ptrnext !=NULL)
4.6.2.1. ptr  ptrnext
4.6.3. ptrnext newnode
5. increment i
6.call display function.
DISPLAY():
1. if(head==NULL) else goto 2
1.1. print “List is empty”.
2. else
2.1. ptrhead
2.2. print “list element”
2.3. if (ptr !=NULL)
2.3.1. print the data
2.3.2. ptr  ptr  next.

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. ptrhead.
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. newnodenext 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.ptrhead
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 (headnextNULL) 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. ptrhead
3.2.if ( ptrnext!=NULL)
3.2.1. tempptr
3.2.2.ptr ptr next
4.tempnextNULL
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. ptrfindprevious(element)
3.3. temp ptr next
3.4. ptrnext temp next
3.5. print deleted element
3.6. free (temp)
4.call display function
SEARCH ():
1.ptr  head
2. if (ptr!=NULL && ptrdata!=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”

You might also like