 Hello everyone. Myself, Mr. F. R. Sayed, I work as an assistant professor in the department of computer science and engineering at Walsh and Institute of Technology, Swallapur. The topic for my today's lecture is deleting a node from the beginning of a singly linked list. Now, the learning outcome at the end of the session, the students will be able to write a C program for deleting a node from the beginning of a singly linked list. Now, let us first see what is a linked list? A linked list is actually a collection of nodes. Now, let us see what are the fields that are there in a node. A node actually has two types of fields. One field is a data field that actually consists of the data to be stored and the second field is a pointer to the next node in the linked list. Now, actually we have two different types of pointers in a linked list. That is the pointer to the first node in the linked list is actually called as the start and the pointer to the last node in the linked list is called as the tail. Now, this tail pointer is optional, but we need to compulsorily have the start pointer so that with the help of the start pointer, the other nodes of the linked list can be reached. Now, when the list is initially empty, we can say that the start pointer will point to null indicating that there are no nodes present in the linked list. Now, there are four types of linked list. The first one is the singly linked list that we are going to see in this lecture. The second one is the doubly linked list where we will be having actually two pointers that is one pointer to the next node of the linked list and one pointer to the previous node of the linked list. Similarly, we have another type of linked list that is the circular linked list where we can say the next pointer of the last node will be pointing to the first node of the linked list. So, therefore, the named as circular linked list and in that circular linked list, we have two different categories that is singly circular linked list and the doubly circular linked list. The singly circular linked list actually a singly linked list where the next pointer of the last node will point to the first node and the W circular linked list is a doubly linked list where the next pointer of the last node will be pointing to the first node and the previous pointer of the first node will be pointing to the last node of the linked list. Let us see exactly what are the different fields of the singly linked list? As we know that there is a data field and the pointer to the next node. So, in a singly linked list there will be only one pointer that will point to the next node whereas As we know, in a doubly linked list, there will be two pointers, one pointing to the next node and one pointing to the previous node. Now this is true for all the nodes of the linked list. So here we have a diagram that indicates a singly linked list. And you can see the first node has a data 5, then the next node has data 10, 21 and so on. Now every node has a next pointer that points to the next node of the linked list and the next pointer of the last node actually points to null. So it indicates that here it ends the linked list. So if you are going to implement this with a programming, we are going to make use of struct node where we are going to have two fields that is one is data field of the data type integer and the second one is will be struct node star next that is a pointer that will point to the next node of the linked list. So now today we will be seeing the operation of deleting a node from the beginning or from the start of the linked list. Let us first see its algorithm. Now suppose if we are having some elements in our linked list and we intend to delete a node from the beginning of the linked list. So for that we have this algorithm. So first of all we will start our algorithm and then we are going to declare a pointer temp and we are going to make the pointer temp to point to the current start node that is the first node in the linked list. Now there might be two conclusions. Temp could be either equal to null now or it will not be equal to null. If temp is equal to null it indicates that the list is empty because we know we have just initialized temp to start. Then in that case we will just display a list as empty otherwise if there are at least one node in the linked list then we are going to make the start pointer to move ahead and point to the next node if at all any node is available after the first node. That means we may be having two or more nodes in our linked list but even if we have only one node in the linked list in that case also we are going to move our start pointer by making start equal to start arrow next. And then we are going to free the memory that has been pointed to by the temp pointer so that it will get unallocated. It will get deallocated and then we are going to stop. Now consider this following sequence of insertion operations on the single linked list. If suppose we are going to insert elements in the linked list in this order that first of all we are going to insert 31 then insert 25 but we know 31 should be inserted at the beginning 25 at the end then 65 at the beginning and then 22 at the end. So the question is what will be the elements in the linked list if suppose the delete from the beginning operation is initiated that is if a node is deleted from the beginning. So now students are expected to pause the video and write the answer to this question. So we will see now one by one initially 31 is added at the beginning then 25 is added at the end then 65 is added at the beginning then 22 is added at the end of the linked list. And then when you have the linked list of elements in this order then in that case if a node is deleted from the beginning in that case 65 should be deleted. So then we have as answer this linked list having the elements 31, 25 and 22 in the linked list after the node is deleted from the beginning. Okay so since we are going to write a program to delete a node from the beginning we should have already taking the code where we have functions declared as for inserting a node at the beginning and inserting a node at the end. So in this program I will just add one more functions prototype declaration for deleting a node from the beginning. So struct node star delete from the beginning and then a parameter of the type struct node star which well is nothing but the start pointer. So we have header files declared we have the node defined over here we have prototype declarations for insert from the beginning insert from the end functions and also we have now declared the delete from the beginning functions prototype we have also declared the prototype for display function then in the main function we have declared a pointer start initialize it to null. Then we have a menu driven program where we can say we are having the options of insert at the beginning insert at the end and then I will add the third option delete from beginning and then option 4 for display option 5 for exit and then I ask the user for enter your choice then I read the user choice in ch variable then of course in the switch case block in the switch case block switch I am taking the variable value of ch then for case 1 for inserting element at the beginning then case 2 for inserting an element at the end and so here I will just insert case 3 for deleting from the beginning a node and of course I will pass the value of start to it and then the brick. But one important thing when delete from beginning function is called it will return some value of the updated start if at all it is updated. So, I need to take it in the start variable once again. So, start equal to delete beginning by passing the value of start and then I have case 4 for display case 5 for exit and default displaying the wrong choice. Similarly, there is the insert from the beginning function defined over here we also have the insert from the end function also defined over here that we have seen already in the initial in the previous videos. So, here I will be including another function for delete from the beginning. So, struct node star delete from beginning here it takes a parameter of the data type struct node star I will name the variable as s it is nothing, but will be holding the value of the start pointer. So, first of all I will declare a pointer as struct node star temp then I will initialize temp equal to s and then I will check if temp equal to null meaning that the link list is empty in that case I will just display a line print f list is empty. Otherwise what we can do is we can just make s equal to s arrow next meaning I will move the start pointer ahead and then I will just print the value being deleted in the print f line percentage d is deleted and percentage d will be replaced with temp arrow data. So, before freeing the temp pointer I will just display the data that is being deleted with the help of temp arrow data and finally, I will write a line of free temp and ultimately I will return the value of s. So, one more line needs to be added over here if the list is empty after displaying that the list is empty immediately we are going to return the value of s. So, now I will run the code I will insert at the beginning elements as 10 then I insert from the end element as 50 I will display the list of elements you have 10 and 50 in the list then once again if I try to add an element at the beginning the element of 30. So, the display function will show the elements as 30, 10, 50 and if I want to add 70 at the end I will add it now. So, then I will try to display the list of elements it is 30, 10, 50 and 70. So, now if I want to delete an element from the beginning. So, I press the option number 3 to see yes 30 is deleted now after I display the list of elements you can see that the element 30 is deleted. So, once again if I want to delete an element from the beginning I think now this time 10 should be deleted yes it says 10 is deleted and then when I display it shows me that the element 10 is gone. So, that is the program for deleting node from the beginning. Now, this is the reference used for the video lecture. Thank you.