 Hello everyone, my name is Nikhil Gadjam working as assistant professor in department of computer science and engineering in Valchand Institute of Technology, Solapur. In this video we will see a display of singly circular linked list in forward as well as in reverse direction. Learning outcome at the end of this session students will be able to write a CE program to display singly circular linked list in forward as well as in reverse direction. Now this is singly circular linked list where linked list contains some nodes and last nodes next part will always holds the address of head or a start that becomes a circular. Now we will see an algorithm for displaying singly circular linked list in forward direction. Step one, if the linked list is empty we will simply return. You cannot display the nodes when singly circular linked list is empty in that case we are directly returning from the function otherwise declare one temporary pointer called a stamp for traversing from first load to the last node. Initialize stamp to the start so it will start, stamp will point to the first node so first node how to point to the first node using start variable where start is my global variable. Traverse stamp till temp arrow next is not equal to start so you will traverse stamp in forward direction from first node to the last node. Now how to find out whether it is last node or not last nodes next part will contains address of start so that is why we have used a condition called as traverse stamp till temp arrow next is equal to start. So once a temp is pointing to the last node we will print and we will returning from that function. While traversing you print temp arrow data every time while traversing. So this is an algorithm for displaying singly circular linked list in forward direction. Now second algorithm is for displaying singly circular linked list in reverse direction. So there are multiple approaches to print the singly circular linked list in reverse direction. You can use a recursion or you can print singly circular linked list in reverse direction without using recursion also. So this is an algorithm for printing singly circular linked list in reverse direction. So first step is to check whether a linked list is empty in that case you are simply returning from the function. Otherwise check whether next node to the current node is head or not or start or not which implies that a current node is pointing to the last node or tell. Then you are printing the data and returning. Where you are returning from where you have called this function. Recursively call reverse function by considering the node next to the current node and print every time nodes arrow data in reverse order starting from the tail. Suppose we will take this diagram. So what you are doing you are traversing temp in forward direction first. You are not printing while traversing. You are go on calling or pointing to the next node one by one using recursive function call. Once a temporary pointer points to the last node in that case you start printing from last node. Once data from the last node you have printed you are returning back to the previous function call. Then again you are printing. Then you are returning to the previous function call. Then again you are printing. So by this way you can print 3, 2 and 1 or you can print all nodes in reverse direction. So this is a recursive algorithm we have used for printing a singly circular linked list in reverse direction. You can answer this question. You can pause the video and you can answer. We can traverse the whole circular linked list by starting from any point to our faults. You have to state whether this statement is true or false. The answer is we can traverse the whole circular linked list starting from any point. Answer is false. You cannot traverse the singly circular linked list or any circular linked list from any point. For traversing you require a global pointer and generally we are using only one global pointer called as start which always points to the first node. So using first node you can traverse. Now we will see a program or we will write a code for displaying singly circular linked list in forward direction as well as in reverse direction. Suppose this is a main. Now this contains four cases. Case one is for insert at beginning which is already implemented. Case two is for display in forward direction which we are implementing now. Case three is display reverse which again we are implementing now and case four is for exit. Insert at beginning we have already code for insert at beginning which we insert the code at the beginning of singly circular linked list. Now display function we will write now. Initialize one temporary pointer for traversing. Again don't use a start pointer for traversing. Start is a global pointer which always points to the first node. You cannot change the value present inside a start. Now this is a struct node star temp. I will use a do while loop or you can use a while loop also. So this is do while this temp is not equal to start. Means a temp will start from a first node and it will traverse the complete singly circular linked list and it will come out of this do while loop when temp again reaches to start or first node. So every time you print. So this is printf this is %d, temp arrow data. This is temp equal to temp arrow next. So this is a display function initially declare a temp as a temporary pointer. Initialize temp to the start. So temp equal to start. So initially temp will point to the first node. This is a do loop, do while loop. So first it will print and it will move forward and this will do while loop. This loop will run till temp reaches again to the first node. It will go on traversing and visiting one by one node from this singly-singly circular linked list and it will come out of this do while loop when temp again reaches to a start or first node. We will execute this function first and we will checking whether this function is correct or not. Just a second display reverse semicolon. I will insert some nodes, insert singly-singly circular linked list. Suppose I want to insert as 44 at the beginning, next one is 33 at the beginning, again next one as 22 at the beginning. Now I will call a display function. Now it is printing 22, 33 and 44. So whatever function we have written for display that code is correct. It is printing a singly-singly circular linked list in forward. Now we will write a code for a function called as display reverse which will display the singly-singly circular linked list in reverse order. So this is my display reverse function which will accept one argument called as temp. So this is the first one you are checking whether temp has reached to the last node or not. Now to find out whether temp has reached to last node or not, if temp arrow next if that double equal to start indicating that temp has reached to the last node. What you have to do? You have to print the data. So this is your printf %d, temp arrow data. So I will give some space and then return. So once temp has reached to the last node you are printing the value from that node of where temp is pointing. So else means temp has not reached to the last node. In that case you are going calling the same function recursively with next nodes address you are passing. So this is your display reverse and what you are passing temp arrow next. And then last one is your printf this is %d, temp arrow data. So what will be the exit condition in this function when temp has reached to the last node. In that case this recursive call will be ended. And then you start printing one by one data and return to the previous function call. We will execute this code and we will check whether this function is executing correctly or not. Just a second we have 1, 2, 3 so we don't have this one. So case one is for insert at beginning. So I will insert some nodes suppose 55, then 44 and then 33. Suppose you call a display function which will display the singly circular link list in forward direction. So we have a link list like this 33, 44 and 55. Suppose I will call a display reverse function in that case now 55, 44 and 33. Now it is printing in reverse direction. So in this program we have written 2 functions display in forward direction without using recursion and next one is display in reverse direction using recursion presentation. Now these are some of the references I have used for creating this video. Thank you.