Algorithm for circular linked list
step1:create a structure containing data part and link part.
Step2:read the case
step3:case1,perform insertfront function
case2,perform insertend function
case3,perform insertany function
case4,perform deletefront function
case5,perform deleteend function
case6,perform deleteany function
case7,exit
insertfront function
1. Create the new node
2. Set the new node’s next to itself (circular!)
3. If the list is empty,return new node.
4. Set our new node’s next to the front.
5. Set tail’s next to our new node.
6. Return the end of the list.
insertatany function
1:creating an new node
2:if newnode=null then print memory underflow
3:else
search for the given location
4:insert node at given location
5:put newnode's link in next node
6:return the end of the list
insertend function
1. Create the new node
2. Set the new node’s next to itself (circular!)
3. If the list is empty,return new node.
4. Set our new node’s next to the front.
5. Set tail’s next to our new node.
6. Return the end of the list.
deletefront function
1. Check whether list is Empty (head == NULL)
2. If it is Empty then, display 'List is Empty!!! Deletion is not possible' and terminate the function.
3. If it is Not Empty then, define two Node pointers 'temp1' and 'temp2' and initialize both 'temp1' and 'temp2' with head.
4. Check whether list is having only one node (temp1 → next == head)
5. If it is TRUE then set head = NULL and delete temp1 (Setting Empty list conditions)
6. If it is FALSE move the temp1 until it reaches to the last node. (until temp1 → next == head )
7. Then set head = temp2 → next, temp1 → next = head and delete temp2
deleteend function
1. Check whether list is Empty (head == NULL)
2. If it is Empty then, display 'List is Empty!!! Deletion is not possible' and terminate the function.
3. If it is Not Empty then, define two Node pointers 'temp1' and 'temp2' and initialize 'temp1' with head.
4. Check whether list has only one Node (temp1 → next == head)
5. If it is TRUE. Then, set head = NULL and delete temp1. And terminate from the function. (Setting Empty list condition)
6. If it is FALSE. Then, set 'temp2 = temp1 ' and move temp1 to its next node. Repeat the same until temp1 reaches to the last node in the list. (until temp1 → next == head)
7. Set temp2 → next = head and delete temp1.
deleteany function
1.Check whether list is Empty (head == NULL)
2.If it is Empty, then display 'List is Empty!!!'and terminate the function.
3. If it is Not Empty then, define a Node pointer 'temp' and initialize with head.
4.Keep displaying temp → data with an arrow (--->) until temp reaches to the last node
5.Finally display temp → data with arrow pointing to head → data.
Step4: Stop
Comments
Post a Comment