{"id":5792,"date":"2021-10-14T11:14:27","date_gmt":"2021-10-14T11:14:27","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=5792"},"modified":"2022-03-11T23:55:24","modified_gmt":"2022-03-11T23:55:24","slug":"deleting-a-node-in-a-linked-list-in-c","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/","title":{"rendered":"Deleting A Node In A Linked List In C"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012084665-Article_199.png\" alt=\"\" \/><\/p>\n<h3>Introduction<\/h3>\n<p>The linked list is one of the most important concepts and data structures to learn while preparing for interviews. Having a good grasp of Linked Lists can be a huge plus point in a coding interview.<\/p>\n<\/p>\n<h3>Problem Statement<\/h3>\n<p>Delete a node with a given key from the given linked list and in case there are multiple occurrences of a given key in the linked list, then delete the first occurrence of this key in the linked list.<\/p>\n<h3>Problem Statement Understanding<\/h3>\n<p>According to the problem statement, we are given a linked list and we have to delete a node with a given key value, it may be present anywhere in the linked list but, there can be two different situations are first being when there is more than one node having the same key and the next being when the node is not at all present in the linked list, so now, you all might think that what we need to do?<\/p>\n<p>In the case where there are multiple nodes, you will just have to delete the first node in the linked list with the value equal to the key, and in the case where the node to be deleted is not present at all in the linked list then simply return and exit the program.<\/p>\n<p>Now, let us understand this problem by taking a very simple example:<\/p>\n<p>If the given linked list is:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/10\/input.png\" alt=\"\" \/><\/p>\n<p><strong>key<\/strong> = 7<\/p>\n<ul>\n<li>According to the problem statement, we have been provided a linked list and a <strong>key<\/strong>, and we need to delete the <strong>key<\/strong> from the given linked list.<\/li>\n<li>As we can see in the above example, 7 is present in the linked list which needs to be deleted.<\/li>\n<li>So after deleting the key from the linked list, the resultant linked list will be:<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/10\/output-1.png\" alt=\"\" \/><\/p>\n<p>Let&#8217;s see another example:<\/p>\n<p>If the given linked list is: 1 \u2192 2 \u2192 3 \u2192 4 \u2192 5 and <strong>key<\/strong> = 4<\/p>\n<ul>\n<li>According to the problem statement, we have been provided a linked list and a <strong>key<\/strong>, and we need to delete the <strong>key<\/strong> from the given linked list.<\/li>\n<li>As we can see in the above example, 4 is present in the linked list which needs to be deleted.<\/li>\n<li>So after deleting the key from the linked list, the resultant linked list will be 1 \u2192 2 \u2192 3 \u2192 5.<\/li>\n<\/ul>\n<p>Now I think from the above examples, the problem is clear. So let\u2019s see how we can approach it.<\/p>\n<p>Before moving to the approach section, try to think about how you can approach this problem.<\/p>\n<ul>\n<li>If stuck, no problem, we will thoroughly see how we can approach this problem in the next section.<\/li>\n<\/ul>\n<p>Let\u2019s move to the approach section. Now, first, let\u2019s discuss the recursive approach to this problem and understand how it works, we will simply follow the steps to understand initially how recursion works for deleting a node from the linked list.<\/p>\n<h3>Approach: (Recursive)<\/h3>\n<ul>\n<li>Now, if we think carefully, the current node is accessed by the previous node\u2019s next, which is passed by reference. Thus, we can say that if we update the current node, previous node\u2019s next will also get updated.<\/li>\n<li>So, we will traverse the linked list with the help of recursion, and when the data of head is equal to the value to be deleted, we will store the head in del_node, do head = head \u2192 next and then delete del_node and then return and terminate the function as our task is completed.<\/li>\n<li>By doing the above steps, the node will get deleted and as discussed above, when we will do head = head \u2192 next, it will make the previous \u2192 next point to head \u2192 next.<\/li>\n<\/ul>\n<p>I hope the above approach might have just given you the basic idea of how recursion will work here, so now let\u2019s look at the algorithm for this method<\/p>\n<h3>Algorithm: (Recursive)<\/h3>\n<p>Now, let\u2019s completely understand the algorithm behind the recursive method, and we will simply follow the steps to delete the node with the given key.<\/p>\n<ul>\n<li>Create a function <strong>deleteNodeWithKey<\/strong> to delete the node with the given key and pass head by reference to the function and the key.<\/li>\n<li>Check if head is NULL, that means the list is empty or the node to be deleted is not in the list. Simply, return.\n<ul>\n<li>Else, check if *<em>((<\/em>head)-&gt;val == key)<strong>, that means current node is the node to be deleted. Now, create a temporary variable <\/strong>del_node<strong> to store the node to be deleted. Now free <\/strong>del_node*<em> variable and update <\/em>head = (*head)-&gt;next; so that previous node&#8217;s next become head-&gt;next and return.<br \/>\nAs we know that the current node is accessed by the previous node\u2019s next, which is passed by reference. hus, we can say that if we update the current node, previous node\u2019s next will also get updated.<\/p>\n<ul>\n<li>Else, Recursively call the function deleteNodeWithKey and pass the reference to the next node in the linked list *<em>deleteNodeWithKey(&amp;((<\/em>head)-&gt;next), key);**.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>Dry run<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/10\/p_1_1_1_2.png\" alt=\"\" \/><\/p>\n<h3>Code<\/h3>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_5793 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_5793 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_5793 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_5793 .wpsm_nav-tabs > li.active > a, #tab_container_5793 .wpsm_nav-tabs > li.active > a:hover, #tab_container_5793 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_5793 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_5793 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_5793 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_5793 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_5793 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_5793 .wpsm_nav-tabs > li > a:hover , #tab_container_5793 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_5793 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_5793 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_5793 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_5793 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_5793 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_5793 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_5793 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5793 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_5793 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5793 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_5793 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_5793\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_5793\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_5793_1\" aria-controls=\"tabs_desc_5793_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_5793\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_5793_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"c\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n\r\n\/\/ A linked list node\r\nstruct Node {\r\n\tint val;\r\n\tstruct Node* next;\r\n};\r\n\/\/ Function to insert the node\r\nvoid pushNode(struct Node** head_ref, int data)\r\n{\r\n\tstruct Node* new_node\r\n\t\t= (struct Node*)malloc(sizeof(struct Node));\r\n\tnew_node->val = data;\r\n\tnew_node->next = (*head_ref);\r\n\t(*head_ref) = new_node;\r\n}\r\n\r\n\/\/ Function to delete the node with the given key\r\nvoid deleteNodeWithKey(struct Node** head, int key)\r\n{\r\n\t\/\/ If head is NULL, then the list is empty\r\n\tif (head == NULL) {\r\n\t\treturn;\r\n\t}\r\n\r\n\t\/\/ If current node is the node to be deleted \r\n\tif ((*head)->val == key) {\r\n\t\tstruct Node* del_node = (*head);\r\n        *head = (*head)->next;\r\n        free(del_node);\r\n        return;\r\n\t}\r\n\t\r\n\tdeleteNodeWithKey(&((*head)->next), key); \/\/ Recursively call the function passing the reference and key to the node\r\n}\r\n\r\n\/\/ Print the linked list\r\nvoid printList(struct Node* node)\r\n{\r\n\twhile (node != NULL) {\r\n\t\tprintf(\" %d \", node->val);\r\n\t\tnode = node->next;\r\n\t}\r\n}\r\n\r\n\/\/Print the linked list after deletion\r\nvoid printListPostDeletion(struct Node* node)\r\n{\r\n\twhile (node != NULL) {\r\n               \tif(node->val != 0)\r\n\t\t\tprintf(\" %d \", node->val);\r\n\t\tnode = node->next;\r\n\t}\r\n}\r\n\r\n\/\/ Driver code\r\nint main()\r\n{\r\n\t\/* Start with the empty list *\/\r\n\tstruct Node* head = NULL;\r\n\r\n\tpushNode(&head, 1);\r\n\tpushNode(&head, 5);\r\n\tpushNode(&head, 7);\r\n\tpushNode(&head, 15);\r\n    pushNode(&head, 20);\r\n    printf(\"Linked list before deleting the key&#92;n\");\r\n\tprintList(head);\r\n\tprintf(\"&#92;n\");\r\n\tdeleteNodeWithKey(&head, 7);\r\n    printf(\"Linked list after deleting the key&#92;n\");\r\n\tprintListPostDeletion(head);\r\n\treturn 0;\r\n}\r\n\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\r\n\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_5793 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_5793 a\"),jQuery(\"#tab-content_5793\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p><strong>Output<\/strong><br \/>\nLinked list before deleting the key<br \/>\n20 \u2192 15 \u2192 7 \u2192 5 \u2192 1<br \/>\nLinked list after deleting the key<br \/>\n20 \u2192 15 \u2192 5 \u2192 1<\/p>\n<p><strong>Time Complexity<\/strong>: The time complexity of this algorithm will be O(n), where n is the number of nodes in the given linked list<\/p>\n<p><strong>Space Complexity<\/strong>: The space complexity of the above algorithm will be O(n) due to recursion.<\/p>\n<p>Now, let&#8217;s see iterative approach.<\/p>\n<h3>Approach (Iterative Method)<\/h3>\n<p>Now, let us discuss the most common and easiest approach to delete a node from the linked list.<\/p>\n<ul>\n<li>Iterate to the node which is present just before the node to be deleted.<\/li>\n<li>Now, set the next of the current node to the next of the node to be deleted.<\/li>\n<li>Then, free the memory of the node to be deleted.<\/li>\n<\/ul>\n<p>Now, you all might be a bit clear from the approach on what we need to do exactly right?<\/p>\n<p>Now, to get a bit more clear understanding of the implementation let us have a look at the algorithm which explains the full operation step by step<\/p>\n<h3>Algorithm (Iterative Method)<\/h3>\n<p>Now, let\u2019s understand the algorithm on how to implement and think upon the code which we have to write for solving the given problem:<\/p>\n<ul>\n<li>Declare a pointer <strong>node_itr<\/strong> which will initially point to <strong>head<\/strong> and will be used to iterate through the linked list which will help us to find the node to be deleted and another pointer <strong>prev_node<\/strong> which will initially point to NULL and point to the previous node of the node which has to be deleted.<\/li>\n<li>Now, check if <strong>node_itr<\/strong> is not NULL and <strong>node_itr-&gt;data==key<\/strong> that means the key to be deleted is the head node, then we will change the reference to the head node to the next node of <strong>node_itr<\/strong> and delete <strong>node_itr<\/strong> and return.<\/li>\n<li>Else, move <strong>node_itr<\/strong> forward and also keep track of previous node <strong>node_prev = node_itr<\/strong> and search for the node with the given key to be deleted in the linked list.<\/li>\n<li>Now, if <strong>node_itr<\/strong> becomes NULL that means the node is not present in the given linked list then simply return and end the process.<\/li>\n<li>Else, point the next of the <strong>prev_node<\/strong> to next of <strong>node_itr<\/strong>, the node which has to be deleted, and finally delete the node.<\/li>\n<\/ul>\n<h3>Dry Run:<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/10\/input.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/10\/p_1_3.png\" alt=\"\" \/><\/p>\n<h3>Code Implementation<\/h3>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_5794 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_5794 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_5794 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_5794 .wpsm_nav-tabs > li.active > a, #tab_container_5794 .wpsm_nav-tabs > li.active > a:hover, #tab_container_5794 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_5794 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_5794 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_5794 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_5794 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_5794 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_5794 .wpsm_nav-tabs > li > a:hover , #tab_container_5794 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_5794 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_5794 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_5794 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_5794 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_5794 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_5794 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_5794 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5794 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_5794 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5794 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_5794 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_5794\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_5794\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_5794_1\" aria-controls=\"tabs_desc_5794_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C++<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_5794\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_5794_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"c\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n\r\nstruct Node {\r\n    int data;\r\n    struct Node* next;\r\n};\r\n\r\nvoid pushNode(struct Node** head_ref, int data)\r\n{\r\n    struct Node* new_node\r\n        = (struct Node*)malloc(sizeof(struct Node));\r\n    new_node->data = data;\r\n    new_node->next = (*head_ref);\r\n    (*head_ref) = new_node;\r\n}\r\n\r\n\/\/ Function to delete the node with given key\r\nvoid deleteGivenNode(struct Node** head_ref, int key)\r\n{\r\n    struct Node *node_itr = *head_ref, *prev_node;\r\n\r\n    if (node_itr != NULL && node_itr->data == key) {\r\n        *head_ref = node_itr->next;\r\n        free(node_itr);\r\n        return;\r\n    }\r\n\r\n    while (node_itr != NULL && node_itr->data != key) {\r\n        prev_node= node_itr;\r\n        node_itr= node_itr->next;\r\n    }\r\n\r\n    if (node_itr == NULL)\r\n        return;\r\n\r\n    prev_node->next = node_itr->next;\r\n\r\n    free(node_itr);\r\n}\r\n\r\n\/\/Function to print the linked list\r\nvoid printList(struct Node* node)\r\n{\r\n    while (node != NULL) {\r\n        printf(\" %d \", node->data);\r\n        node = node->next;\r\n    }\r\n}\r\n\r\nint main()\r\n{\r\n    struct Node* head = NULL;\r\n\r\n    pushNode(&head, 1);\r\n    pushNode(&head, 5);\r\n    pushNode(&head, 7);\r\n    pushNode(&head, 15);\r\n    pushNode(&head, 20);\r\n    \r\n    printf(\"Linked list before deleting the key&#92;n\");\r\n    printList(head);\r\n    printf(\"&#92;n\");\r\n    printf(\"Linked list after deleting the key&#92;n\");\r\n    deleteGivenNode(&head, 1);\r\n    printList(head);\r\n    return 0;\r\n}\r\n\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\r\n\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_5794 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_5794 a\"),jQuery(\"#tab-content_5794\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p><strong>Output<\/strong><br \/>\nLinked list before deleting the key<br \/>\n20 \u2192 15 \u2192 7 \u2192 5 \u2192 1<br \/>\nLinked list after deleting the key<br \/>\n20 \u2192 15 \u2192 7 \u2192 5<\/p>\n<p><strong>Time Complexity<\/strong>: The time complexity of this algorithm will be O(n), where n is the number of nodes in the given linked list<\/p>\n<p><strong>Space Complexity<\/strong>: The space complexity of the above algorithm will be O(1) as we are not using any additional data structure to manipulate the nodes<\/p>\n<p>So, in this article, we have tried to explain the most efficient approach to flatten a binary tree to a linked list. This is an important question when it comes to coding interviews. If you want to solve more questions on Linked List, which are curated by our expert mentors at PrepBytes, you can follow this link <a href=\"https:\/\/mycode.prepbytes.com\/interview-coding\/practice\/linked-list\">Linked List<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction The linked list is one of the most important concepts and data structures to learn while preparing for interviews. Having a good grasp of Linked Lists can be a huge plus point in a coding interview. Problem Statement Delete a node with a given key from the given linked list and in case there [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-5792","post","type-post","status-publish","format-standard","hentry","category-c-programming"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Deleting A Node In A Linked List In C | C Programming | PrepBytes Blog<\/title>\n<meta name=\"description\" content=\"Learn the most efficient way to delete a given node in a linked list.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Deleting A Node In A Linked List In C | C Programming | PrepBytes Blog\" \/>\n<meta property=\"og:description\" content=\"Learn the most efficient way to delete a given node in a linked list.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/\" \/>\n<meta property=\"og:site_name\" content=\"PrepBytes Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prepbytes0211\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-10-14T11:14:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-03-11T23:55:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012084665-Article_199.png\" \/>\n<meta name=\"author\" content=\"PrepBytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"PrepBytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/\"},\"author\":{\"name\":\"PrepBytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e\"},\"headline\":\"Deleting A Node In A Linked List In C\",\"datePublished\":\"2021-10-14T11:14:27+00:00\",\"dateModified\":\"2022-03-11T23:55:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/\"},\"wordCount\":1345,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012084665-Article_199.png\",\"articleSection\":[\"C Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/\",\"name\":\"Deleting A Node In A Linked List In C | C Programming | PrepBytes Blog\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012084665-Article_199.png\",\"datePublished\":\"2021-10-14T11:14:27+00:00\",\"dateModified\":\"2022-03-11T23:55:24+00:00\",\"description\":\"Learn the most efficient way to delete a given node in a linked list.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012084665-Article_199.png\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012084665-Article_199.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C Programming\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/c-programming\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Deleting A Node In A Linked List In C\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/43.205.93.38\/#website\",\"url\":\"http:\/\/43.205.93.38\/\",\"name\":\"PrepBytes Blog\",\"description\":\"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING\",\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/43.205.93.38\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/43.205.93.38\/#organization\",\"name\":\"Prepbytes\",\"url\":\"http:\/\/43.205.93.38\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"contentUrl\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"width\":160,\"height\":160,\"caption\":\"Prepbytes\"},\"image\":{\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/prepbytes0211\/\",\"https:\/\/www.instagram.com\/prepbytes\/\",\"https:\/\/www.linkedin.com\/company\/prepbytes\/\",\"https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e\",\"name\":\"PrepBytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g\",\"caption\":\"PrepBytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/prepbytes\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Deleting A Node In A Linked List In C | C Programming | PrepBytes Blog","description":"Learn the most efficient way to delete a given node in a linked list.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/","og_locale":"en_US","og_type":"article","og_title":"Deleting A Node In A Linked List In C | C Programming | PrepBytes Blog","og_description":"Learn the most efficient way to delete a given node in a linked list.","og_url":"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2021-10-14T11:14:27+00:00","article_modified_time":"2022-03-11T23:55:24+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012084665-Article_199.png","type":"","width":"","height":""}],"author":"PrepBytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"PrepBytes","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/"},"author":{"name":"PrepBytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e"},"headline":"Deleting A Node In A Linked List In C","datePublished":"2021-10-14T11:14:27+00:00","dateModified":"2022-03-11T23:55:24+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/"},"wordCount":1345,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012084665-Article_199.png","articleSection":["C Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/","url":"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/","name":"Deleting A Node In A Linked List In C | C Programming | PrepBytes Blog","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012084665-Article_199.png","datePublished":"2021-10-14T11:14:27+00:00","dateModified":"2022-03-11T23:55:24+00:00","description":"Learn the most efficient way to delete a given node in a linked list.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012084665-Article_199.png","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012084665-Article_199.png"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/deleting-a-node-in-a-linked-list-in-c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"C Programming","item":"https:\/\/prepbytes.com\/blog\/category\/c-programming\/"},{"@type":"ListItem","position":3,"name":"Deleting A Node In A Linked List In C"}]},{"@type":"WebSite","@id":"http:\/\/43.205.93.38\/#website","url":"http:\/\/43.205.93.38\/","name":"PrepBytes Blog","description":"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING","publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/43.205.93.38\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/43.205.93.38\/#organization","name":"Prepbytes","url":"http:\/\/43.205.93.38\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/","url":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","contentUrl":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","width":160,"height":160,"caption":"Prepbytes"},"image":{"@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/prepbytes0211\/","https:\/\/www.instagram.com\/prepbytes\/","https:\/\/www.linkedin.com\/company\/prepbytes\/","https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA"]},{"@type":"Person","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e","name":"PrepBytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g","caption":"PrepBytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/prepbytes\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5792","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=5792"}],"version-history":[{"count":6,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5792\/revisions"}],"predecessor-version":[{"id":8050,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5792\/revisions\/8050"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=5792"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=5792"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=5792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}