 Hello everyone, my name is Nikhil Gadjum working as assistant professor in department of computer science and engineering in Valchand Institute of Technology, Solapur. In today's video, we will see a deletion of node from singly circular linked list. Learning outcome at the end of this session, student will be able to write a C program for deletion of node from singly circular linked list. Now this is the difference between singly linked list and singly circular linked list. In singly linked list, last node's next part will have null to indicate this is the last node or end of the singly linked list. In singly circular linked list, last node's next part, next pointer holds the address of start or holds the address of first node that becomes a circular. So this is a singly circular linked list. Now we will see first algorithm for deletion of node from singly circular linked list. Then we will see a program. Now step one, first task is to check whether a singly linked list is empty or not. If it is an empty, we cannot delete the node from the singly circular linked list. You are simply written from that function. Second step, if singly circular linked list is not empty, then define two pointers. First one is TAMP and second one is PE TAMP. Some programs use three pointers instead of two, but we require two pointers. TAMP will always points to that node which is to be deleted from singly circular linked list. So first initialize TAMP to the start, then traverse TAMP to that node which is to be deleted and set every time PE TAMP equal to TAMP before TAMP is moving forward. So PE TAMP is a previous to TAMP pointer which always points to previous node of TAMP and some programs will have N TAMP also which is next to TAMP which will hold or which will point to the node which is next to TAMP. So after TAMP is pointing to that particular node which is to be deleted, next task now check whether a node to be deleted is first node or not. If it is first node, again you are checking if that singly circular linked list contains only one node, in that case set start equal to null. If singly circular linked list contains only one node and that node is to be deleted, so after deletion of that node singly circular linked list don't contain any node and that will become empty. If singly circular linked list contains more than one node and you want to delete the first node, in that case set PE TAMP at the end of singly circular linked list or point PE TAMP at the end of singly circular linked list. In that case after pointing set PE TAMP arrow next is equal to TAMP arrow next and start equal to TAMP arrow next. So you are deleting the node where TAMP is pointing and last one set if TAMP is not the first node. If node is to be deleted is not the first node, in that case set PE TAMP arrow next is equal to TAMP arrow next and at the last for all these steps write one extra step called as free TAMP. You have to free whatever allocated you have allocated memory for TAMP. So this is algorithm for deleting a node from singly circular linked list. You can pause the video and you can answer this question. In singly circular linked list time complexity for deleting the last node is, you can pause and you can answer for this question is big of n. You cannot point directly to the last node which is to be deleted, you cannot go directly to the last node in singly circular linked list because there is only one pointer which is next pointer. So you have to traverse from first node to the last node for deletion of last node then only you can delete the last node. So complexity time complexity will be obviously big of n because you are traversing n nodes for deletion of last node. Now we will see a program or we will write a function called as delete to delete a particular node from the singly circular linked list. This is online GDB where you can write your code and you can compile and execute. So this is your main function. Now it contains four cases. So case one is for insert at begin, second one is display. These two functions I have already implemented. Now delete function which we are going to write a code right now and exit for exiting from the program. So this is insert at beginning, this is a code, this is a display function. Now delete function we are writing now. First use one variable called as element to take the value from the user which node is to be deleted. So I have taken int element. Next one this is your struct node star temp comma star pre-temp comma star n-temp. n-temp is extra pointer you can take or you can write this code without n-temp also. So first you ask user which node is to be deleted. So this is printf enter data which is to be deleted. This is canf %d comma address of element. Now check if this element is equal to start arrow data means you are checking whether a node is to be deleted is the first node or not. So in that case now first you initialize temp to start and you initialize n-temp is also equal to start. Now traverse n-temp to the last one. Now how to traverse that while this n-temp arrow next is not equal to start n-temp equal to n-temp arrow next. So every time you are moving n-temp till it reach to last node. Now once n-temp is reach to last node in that case n-temp arrow next equal to temp arrow next start equal to start arrow next move start to the next node and next free temp. So you are deleted first node. Now suppose a node which is to be deleted is not the first node right else part means a node which is to be deleted is not the first node in that case you have to traverse n-temp from first node to that node. So this is temp equal to start initialize temp to start now write down while this temp arrow data is not equal to element you have to move temp to the forward direction till temp reaches to that node which is to be deleted. So every time p-temp will point to previous of temp so p-temp equal to temp and temp equal to temp arrow next. So p-temp and temp both will move side by side. So once temp has point to that node which is to be deleted now join the pointer parts how to join p-temp arrow next equal to temp arrow next and last one this is free temp. So what we have done first we have initialized the pointers next we have taken the value which is to be deleted I have stored that inside a variable called as element. Next check whether element is double equal to start arrow data means first node you have to delete then temp equal to start initialize temp and n-temp both to the start then while n-temp arrow next is not equal to start n-temp equal to n-temp arrow next move n-temp to the last node. Once n-temp has reached to last node the next step is n-temp arrow next equal to temp arrow next start equal to start arrow next move start to the next node and free temp which will deallocate the memory which is allocated earlier else part means whatever node which you have to delete which you want to delete that is not the first node in that case. So use while loop to traverse temp to point to that node which is to be deleted. So while temp arrow data is not equal to element p-temp equal to temp and temp equal to temp arrow next then join the pointers p-temp arrow next is equal to temp arrow next and free temp. We will execute this we will check whether this code is working correctly or not. So first I will insert some values insert singly circular linked list. So this is insert at beginning suppose 50 again insert at beginning 40 insert at beginning 30 I will display. So now this singly circular linked list contains 3 nodes 30, 40 and 50. Suppose I want to delete now so I will call delete function which data is to be deleted is suppose I want to delete 40 suppose so I will display call the display function now 40 is deleted from the singly circular linked list now it contains only 2 nodes okay we will move back again to the presentation. So these are some of the references I have used for creating this video. Thank you.