{"id":5288,"date":"2021-09-27T19:40:22","date_gmt":"2021-09-27T19:40:22","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=5288"},"modified":"2022-03-10T19:42:20","modified_gmt":"2022-03-10T19:42:20","slug":"linked-list-deleting-node","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/","title":{"rendered":"Linked List Deleting Node"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007546200-Article_162.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<h3>Problem Statement<\/h3>\n<p>In this question, we are given a singly linked list and a value <strong>X<\/strong>. We have to delete the first occurrence of a node with the data <strong>X<\/strong> from the linked list.<\/p>\n<p><strong>Note:<\/strong> Although there can be multiples nodes with value <strong>X<\/strong> in the linked list, but we have to only delete the first node with value <strong>X<\/strong> from the linked list.<\/p>\n<h3>Problem Statement Understanding<\/h3>\n<p>Let\u2019s try to understand the problem statement with the help of examples.<\/p>\n<p>Suppose the given linked list is: 1 \u2192 1 \u2192 0 \u2192 2 \u2192 2 and the value to be deleted is 0.<\/p>\n<ul>\n<li>Now, according to the problem statement, we have to delete the first occurrence of the node containing the value 0.<\/li>\n<li>So, the linked list after deleting 0 will be 1 \u2192 1 \u2192 2 \u2192 2.<\/li>\n<\/ul>\n<p>Suppose the list is:.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/input-21.png\" alt=\"\" \/><\/p>\n<p>and the value to be deleted is 2<\/p>\n<ul>\n<li>Now, in this case, we can see that there are two nodes with data 2 in the linked list. According to the problem statement, we only need to delete the first occurrence of the node with value 2 from the linked list.<\/li>\n<li>Our output linked list after deletion will be <\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/output-23.png\" alt=\"\" \/><\/p>\n<h5>Some more examples<\/h5>\n<p>Sample Input 1: 1 \u2192 2 \u2192 3 \u21924, Value to be deleted (X) = 2<br \/>\nSample Output 1: 1 \u2192 3 \u2192 4<\/p>\n<p>Sample Input 2: 1 \u2192 1 \u2192 2 \u21922, Value to be deleted (X) = 1<br \/>\nSample Output 2: 1 \u2192 2 \u2192 2<\/p>\n<p>Now, I think from the above examples, the problem statement is clear. Let\u2019s see how we can approach it.<\/p>\n<p>Before moving to the approach section, try to think about how can you 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.<\/p>\n<h3>Approach (Iterative)<\/h3>\n<p>Let us first think about what we should do to delete a node from a linked list.  <\/p>\n<p>Let us take an example.  1 \u2192 2 \u2192 3 \u2192 4. Now, to delete 2 from the list, what should we do? <\/p>\n<ul>\n<li>What if we make 1 point to 3 instead of  2 ? Yes. That\u2019s the essence.<\/li>\n<\/ul>\n<p>To delete a node <strong>P<\/strong> from a linked list, we have to traverse to its previous node and make it point to the <strong>P<\/strong>&#8216;s next node.<\/p>\n<p>Let\u2019s see the algorithm.<\/p>\n<h3>Algorithm<\/h3>\n<ul>\n<li>Create a pointer <strong>temp<\/strong> and make it point to the head of the list and also create a pointer <strong>prev<\/strong> and point it to NULL.<\/li>\n<li>If the head contains the value <strong>X<\/strong>, make <strong>head = temp \u2192 next<\/strong>, and then <strong>delete temp<\/strong>. <\/li>\n<li>Else, we will traverse the list with <strong>temp<\/strong> and store <strong>temp<\/strong> in pointer <strong>prev<\/strong> before incrementing it.\n<ul>\n<li>The loop will run till <strong>temp \u2192 data! = X<\/strong>. <\/li>\n<li>As soon as <strong>temp \u2192 data = X<\/strong>, the loop will break. <\/li>\n<\/ul>\n<\/li>\n<li>As we were storing <strong>temp<\/strong> in <strong>prev<\/strong> before incrementing it, so <strong>prev<\/strong> now points to the previous node of the node which we want to delete. <\/li>\n<li>Now, we will simply do <strong>prev -&gt; next = temp -&gt; next<\/strong>, as discussed in the approach. <\/li>\n<li>Finally, <strong>delete temp<\/strong>. <\/li>\n<li>In this way, the first occurrence of a node with value X will be deleted. If the list is traversed and the value is not found, we will simply return.<\/li>\n<\/ul>\n<h3>Dry Run<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_1-25.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_5289 {\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_5289 .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_5289 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_5289 .wpsm_nav-tabs > li.active > a, #tab_container_5289 .wpsm_nav-tabs > li.active > a:hover, #tab_container_5289 .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_5289 .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_5289 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_5289 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_5289 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_5289 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_5289 .wpsm_nav-tabs > li > a:hover , #tab_container_5289 .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_5289 .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_5289 .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_5289 .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_5289 .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_5289 .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_5289 .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_5289 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5289 .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_5289 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5289 .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_5289 .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_5289\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_5289\">\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_5289_1\" aria-controls=\"tabs_desc_5289_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\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_5289_2\" aria-controls=\"tabs_desc_5289_2\" 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\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_5289_3\" aria-controls=\"tabs_desc_5289_3\" 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>Java<\/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\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_5289_4\" aria-controls=\"tabs_desc_5289_4\" 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>Python<\/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_5289\">\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_5289_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 &lt;stdio.h&gt;\r\n#include &lt;stdlib.h&gt;\r\n \r\n\/\/ A linked list node\r\nstruct Node {\r\n    int data;\r\n    struct Node* next;\r\n};\r\n \r\n\/* Given a reference (pointer to pointer) to the head of a\r\n   list and an int, inserts a new node on the front of the\r\n   list. *\/\r\nvoid push(struct Node** head_ref, int new_data)\r\n{\r\n    struct Node* new_node\r\n        = (struct Node*)malloc(sizeof(struct Node));\r\n    new_node-&gt;data = new_data;\r\n    new_node-&gt;next = (*head_ref);\r\n    (*head_ref) = new_node;\r\n}\r\n \r\n\/* Given a reference (pointer to pointer) to the head of a\r\n   list and a key, deletes the first occurrence of key in\r\n   linked list *\/\r\nvoid deleteNode(struct Node** head_ref, int key)\r\n{\r\n    \/\/ Store head node\r\n    struct Node *temp = *head_ref, *prev;\r\n \r\n    \/\/ If head node itself holds the key to be deleted\r\n    if (temp != NULL &amp;&amp; temp-&gt;data == key) {\r\n        *head_ref = temp-&gt;next; \/\/ Changed head\r\n        free(temp); \/\/ free old head\r\n        return;\r\n    }\r\n \r\n    \/\/ Search for the key to be deleted, keep track of the\r\n    \/\/ previous node as we need to change 'prev-&gt;next'\r\n    while (temp != NULL &amp;&amp; temp-&gt;data != key) {\r\n        prev = temp;\r\n        temp = temp-&gt;next;\r\n    }\r\n \r\n    \/\/ If key was not present in linked list\r\n    if (temp == NULL)\r\n        return;\r\n \r\n    \/\/ Unlink the node from linked list\r\n    prev-&gt;next = temp-&gt;next;\r\n \r\n    free(temp); \/\/ Free memory\r\n}\r\n \r\n\/\/ This function prints contents of linked list starting\r\n\/\/ from the given node\r\nvoid printList(struct Node* node)\r\n{\r\n    while (node != NULL) {\r\n        printf(&quot; %d &quot;, node-&gt;data);\r\n        node = node-&gt;next;\r\n    }\r\n}\r\n \r\n\/\/ Driver code\r\nint main()\r\n{\r\n    \/* Start with the empty list *\/\r\n    struct Node* head = NULL;\r\n \r\n    push(&amp;head, 7);\r\n    push(&amp;head, 1);\r\n    push(&amp;head, 3);\r\n    push(&amp;head, 2);\r\n \r\n    puts(&quot;Created Linked List: &quot;);\r\n    printList(head);\r\n    deleteNode(&amp;head, 1);\r\n    puts(&quot;&#92;nLinked List after Deletion of 1: &quot;);\r\n    printList(head);\r\n    return 0;\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_5289_2\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"cpp\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include &lt;bits\/stdc++.h&gt;\r\nusing namespace std;\r\n\r\n\/* Node structure of linked list node *\/\r\nclass Node{\r\npublic:\r\n    int data;\r\n    Node* next;\r\n};\r\n\r\n\/* Using this function we will insert a new node at head of linked list *\/\r\nvoid push(Node** head_ref, int new_data)\r\n{\r\n    Node* new_node = new Node();\r\n    new_node-&gt;data = new_data;\r\n    new_node-&gt;next = (*head_ref);\r\n    (*head_ref) = new_node;\r\n}\r\n\r\n\/* Using this function we will be deleting the first occurance of a node with value = key from the linked list *\/\r\nvoid deleteValue(Node** head_ref, int key)\r\n{\r\n    \r\n    Node* temp = *head_ref;\r\n    Node* prev = NULL;\r\n\r\n    if (temp != NULL &amp;&amp; temp-&gt;data == key)\r\n    {\r\n        *head_ref = temp-&gt;next; \r\n        delete temp;         \r\n        return;\r\n    }\r\n\r\n    else\r\n    {\r\n    while (temp != NULL &amp;&amp; temp-&gt;data != key)\r\n    {\r\n        prev = temp;\r\n        temp = temp-&gt;next;\r\n    }\r\n\r\n    if (temp == NULL)\r\n        return;\r\n\r\n    prev-&gt;next = temp-&gt;next;\r\n\r\n    delete temp;\r\n    }\r\n}\r\n\r\n\/* Using this function we will be printing the content of linked list *\/\r\nvoid print(Node* node)\r\n{\r\n    while (node != NULL)\r\n    {\r\n        cout &lt;&lt; node-&gt;data &lt;&lt; &quot; &quot;;\r\n        node = node-&gt;next;\r\n    }\r\n}\r\n\r\nint main()\r\n{\r\n    Node* head = NULL;\r\n    push(&amp;head, 4);\r\n    push(&amp;head, 3);\r\n    push(&amp;head, 2);\r\n    push(&amp;head, 1);\r\n\r\n    puts(&quot;Created Linked List: &quot;);\r\n    print(head);\r\n    \r\n    int X = 2;\r\n    deleteValue(&amp;head, X);\r\n    cout&lt;&lt;&quot;&#92;nLinked List after Deletion of first occurance of node with value &quot;&lt;&lt;X&lt;&lt;&quot;: &quot;&lt;&lt;endl;\r\n    \r\n    print(head);\r\n    \r\n    return 0;\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_5289_3\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"java\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\npublic class LinkedList {\r\n    Node head; \r\n\r\n    \/* Node structure of a linked list node *\/\r\n    class Node {\r\n        int data;\r\n        Node next;\r\n        Node(int d)\r\n        {\r\n            data = d;\r\n            next = null;\r\n        }\r\n    }\r\n    \r\n    \/* Using this function we will be deleting the first occurance of a node with value = key from the linked list *\/\r\n    void deleteValue(int key)\r\n    {\r\n\r\n        Node temp = head, prev = null;\r\n\r\n        if (temp != null &amp;&amp; temp.data == key) {\r\n            head = temp.next;\r\n            return;\r\n        }\r\n\r\n        while (temp != null &amp;&amp; temp.data != key) {\r\n            prev = temp;\r\n            temp = temp.next;\r\n        }\r\n\r\n        if (temp == null)\r\n            return;\r\n\r\n        prev.next = temp.next;\r\n    }\r\n    \r\n    \/* Using this function we will insert a new node at head of linked list *\/\r\n    public void push(int new_data)\r\n    {\r\n        Node new_node = new Node(new_data);\r\n        new_node.next = head;\r\n        head = new_node;\r\n    }\r\n\r\n    \/* Using this function we will be printing the content of linked list *\/\r\n    public void printList()\r\n    {\r\n        Node tnode = head;\r\n        while (tnode != null) {\r\n            System.out.print(tnode.data + &quot; &quot;);\r\n            tnode = tnode.next;\r\n        }\r\n    }\r\n\r\n\r\n    public static void main(String[] args)\r\n    {\r\n        LinkedList llist = new LinkedList();\r\n\r\n        llist.push(4);\r\n        llist.push(3);\r\n        llist.push(2);\r\n        llist.push(1);\r\n\r\n        System.out.println(&quot;&#92;nCreated Linked list is:&quot;);\r\n        llist.printList();\r\n        \r\n        int X = 2;\r\n        llist.deleteValue(X);\r\n\r\n        System.out.println(\r\n            &quot;&#92;nLinked List after Deletion of first occurance of node with value &quot;+X+&quot;: &quot;);\r\n        llist.printList();\r\n    }\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_5289_4\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"python\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\nclass Node:\r\n\r\n\tdef __init__(self, data):\r\n\t\tself.data = data\r\n\t\tself.next = None\r\n\r\nclass LinkedList:\r\n\r\n\tdef __init__(self):\r\n\t\tself.head = None\r\n\r\n\tdef push(self, new_data):\r\n\t\tnew_node = Node(new_data)\r\n\t\tnew_node.next = self.head\r\n\t\tself.head = new_node\r\n\r\n\tdef deleteNode(self, key):\r\n\t\t\r\n\t\ttemp = self.head\r\n\r\n\t\tif (temp is not None):\r\n\t\t\tif (temp.data == key):\r\n\t\t\t\tself.head = temp.next\r\n\t\t\t\ttemp = None\r\n\t\t\t\treturn\r\n\r\n\t\twhile(temp is not None):\r\n\t\t\tif temp.data == key:\r\n\t\t\t\tbreak\r\n\t\t\tprev = temp\r\n\t\t\ttemp = temp.next\r\n\r\n\t\tif(temp == None):\r\n\t\t\treturn\r\n\r\n\t\tprev.next = temp.next\r\n\r\n\t\ttemp = None\r\n\r\n\r\n\tdef printList(self):\r\n\t\ttemp = self.head\r\n\t\twhile(temp):\r\n\t\t\tprint (temp.data, end = &quot; &quot;)\r\n\t\t\ttemp = temp.next\r\n\r\n\r\nllist = LinkedList()\r\nllist.push(4)\r\nllist.push(3)\r\nllist.push(2)\r\nllist.push(1)\r\n\r\nprint (&quot;Created Linked List: &quot;)\r\nllist.printList()\r\nllist.deleteNode(2)\r\nprint (&quot;&#92;nLinked List after Deletion of 2:&quot;)\r\nllist.printList()\r\n\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\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_5289 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_5289 a\"),jQuery(\"#tab-content_5289\"));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<h4>Output<\/h4>\n<p>Created Linked List:<br \/>\n1 2 3 4<br \/>\nLinked List after Deletion of first occurance of node with value 2:<br \/>\n1 3 4 <\/p>\n<p><strong>Time Complexity:<\/strong> O(n), as list traversal is needed.<br \/>\n<strong>Space Complexity:<\/strong> O(1), as only temporary variables are being created.<\/p>\n<h3>Approach (Recursive)<\/h3>\n<p>As we have already discussed what we have to do to delete a node from a linked list, now here we will modify it a lit bit while implementing.<\/p>\n<ul>\n<li>\nIf we think carefully, the current node is accessed by the previous node\u2019s next, which is passed by reference. Thus, we can say that altering the current node can alter the previous node\u2019s next.\n<\/li>\n<li>\nSo, we will traverse the linked list with the help of recursion, and when the head&#8217;s data is equal to the value of node to be deleted(X), we will store the <strong>head<\/strong> in <strong>temp<\/strong>, do <strong>head = head \u2192 next<\/strong> and <strong>delete temp<\/strong> and then return as our task is completed.\n<\/li>\n<li>\nBy doing the above steps, the node will get deleted and as discussed above, when we will do <strong>head = head \u2192 next<\/strong>, it will make the <strong>previous \u2192 next<\/strong> point to <strong>head \u2192 next<\/strong>.\n<\/li>\n<\/ul>\n<p>Let&#8217;s see the algorithm.<\/p>\n<h3>Algorithm<\/h3>\n<ul>\n<li>Base case &#8211; If the <strong>head<\/strong> is NULL, i.e., the node with value <strong>X<\/strong> is not present in the list, so we will print <strong>Element not present in the list<\/strong> and then we will return.<\/li>\n<li>If the <strong>head \u2192 data = X<\/strong>, then store the head in a pointer <strong>temp<\/strong>, do <strong>head = head \u2192 next<\/strong> and <strong>delete temp<\/strong> and then return as our task is completed. This will change the required links too as discussed above.<\/li>\n<li>Keep recurring with <strong>deleteValue( head &#8211; &gt; next, X)<\/strong>.<\/li>\n<\/ul>\n<h3>Dry Run<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_2-25.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_5291 {\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_5291 .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_5291 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_5291 .wpsm_nav-tabs > li.active > a, #tab_container_5291 .wpsm_nav-tabs > li.active > a:hover, #tab_container_5291 .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_5291 .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_5291 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_5291 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_5291 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_5291 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_5291 .wpsm_nav-tabs > li > a:hover , #tab_container_5291 .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_5291 .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_5291 .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_5291 .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_5291 .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_5291 .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_5291 .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_5291 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5291 .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_5291 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5291 .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_5291 .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_5291\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_5291\">\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_5291_1\" aria-controls=\"tabs_desc_5291_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\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_5291_2\" aria-controls=\"tabs_desc_5291_2\" 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\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_5291_3\" aria-controls=\"tabs_desc_5291_3\" 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>Java<\/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\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_5291_4\" aria-controls=\"tabs_desc_5291_4\" 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>Python<\/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_5291\">\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_5291_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\/* Link list node *\/\r\nstruct Node {\r\n    int data;\r\n    struct Node* next;\r\n};\r\n \r\n\/* Recursive Function to delete the entire linked list *\/\r\nvoid deleteList(struct Node* head)\r\n{\r\n    if (head == NULL)\r\n        return;\r\n    deleteList(head->next);\r\n    free(head);\r\n}\r\n \r\n\/* Given a reference (pointer to pointer) to\r\n   the head of a list and an int, push a new\r\n   node on the front of the list. *\/\r\nvoid push(struct Node** head_ref, int new_data)\r\n{\r\n    struct Node* new_node = new Node;\r\n    new_node->data = new_data;\r\n    new_node->next = (*head_ref);\r\n    (*head_ref) = new_node;\r\n}\r\n \r\n\/* Driver program to test count function*\/\r\nint main()\r\n{\r\n    \/* Start with the empty list *\/\r\n    struct Node* head = NULL;\r\n \r\n    \/* Use push() to construct below list\r\n    1->12->1->4->1 *\/\r\n    push(&head, 1);\r\n    push(&head, 4);\r\n    push(&head, 1);\r\n    push(&head, 12);\r\n    push(&head, 1);\r\n    printf(\"&#92;n Deleting linked list\");\r\n    deleteList(head);\r\n   \r\n      \/\/ Since head now points to illgal address, we should set head = NULL:\r\n      head = NULL;\r\n    printf(\"&#92;nLinked list deleted\");\r\n    return 0;\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_5291_2\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"cpp\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include <bits\/stdc++.h>\r\nusing namespace std;\r\n\r\nstruct node {\r\n    int info;\r\n    node* link = NULL;\r\n    node() {}\r\n    node(int a)\r\n        : info(a)\r\n    {\r\n    }\r\n};\r\n\r\n\/* Using this function we will be deleting the first occurance of the given valued node from the linked list *\/\r\nvoid deleteValue(node*& head, int value)\r\n{\r\n\r\n    if (head == NULL) {\r\n        cout << \"Element not present in the list&#92;n\";\r\n        return;\r\n    }\r\n\r\n    if (head->info == value) {\r\n        node* temp = head;\r\n        head = head->link; \r\n        delete (temp);\r\n        return;\r\n    }\r\n    deleteValue(head->link, value);\r\n}\r\n\r\n\/* Using this function we will push the node in the list *\/\r\nvoid push(node*& head, int data)\r\n{\r\n    node* newNode = new node(data);\r\n    newNode->link = head;\r\n    head = newNode;\r\n}\r\n\r\n\/* Using this function we will print the content of linked list *\/\r\nvoid print(node* head)\r\n{\r\n\r\n    if (head == NULL and cout << endl)\r\n        return;\r\n    cout << head->info << ' ';\r\n    print(head->link);\r\n}\r\n\r\nint main()\r\n{\r\n    node* head = NULL;\r\n    push(head, 4);\r\n    push(head, 3);\r\n    push(head, 2);\r\n    push(head, 1);\r\n    \r\n    puts(\"Created Linked List: \");\r\n    print(head);\r\n\r\n    int X = 2;\r\n    deleteValue(head, X);\r\n\r\n    cout<<\"&#92;nLinked List after Deletion of first occurance of node with value \"<<X<<\": \"<<endl;\r\n    print(head);\r\n\r\n    return 0;\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_5291_3\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"java\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\nclass Node\r\n{\r\n    int info;\r\n    Node link =null;\r\n    Node(int info)\r\n    {\r\n        this.info=info;\r\n    }\r\n}\r\n\r\nclass DeletingNode \r\n{\r\n    void push(Node head,int data)\r\n    {\r\n        Node newNode = new Node(data);\r\n        newNode.link = head;\r\n        head=newNode;\r\n    }\r\n    void print(Node head)\r\n    {\r\n        Node temp=head;\r\n        while(temp!=null){\r\n            System.out.print(temp.info+\" \");\r\n            temp=temp.link;\r\n        }\r\n    }\r\n\r\n    void deleteValue(Node head,int value)\r\n    {\r\n        if(head==null || head.link==null)\r\n        {\r\n            System.out.println(\"Element not present in the list\");\r\n            return;\r\n        }\r\n        if(head.link.info==value)\r\n        {\r\n            Node x =head;\r\n            x.link=head.link.link;\r\n            return;\r\n        }\r\n        deleteValue(head.link, value);\r\n    }\r\n    public static void main(String[] args) \r\n    {\r\n        Node head=null;\r\n        DeletingNode ll=new DeletingNode();\r\n        ll.push(head, 4);\r\n        ll.push(head, 3);\r\n        ll.push(head, 2);\r\n        ll.push(head, 1);\r\n\r\n        System.out.println(\"Created linked list :\");\r\n        ll.print(head);\r\n\r\n        int x=2;\r\n        ll.deleteValue(head, x);\r\n\r\n        Node temp=head;\r\n        System.out.println(\"Linked list after deletion of first occurance of node with value \"+x);\r\n        ll.print(temp);\r\n    }\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_5291_4\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"python\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\nclass Node:\r\n\r\n    def __init__(self, data):\r\n        self.data = data\r\n        self.next = None\r\n\r\nclass LinkedList:\r\n\r\n    def __init__(self):\r\n        self.head = None\r\n\r\n    def push(self, new_data):\r\n        new_node = Node(new_data)\r\n        new_node.next = self.head\r\n        self.head = new_node\r\n\r\n\r\n    def printList(self):\r\n        temp = self.head\r\n        while(temp):\r\n            print (temp.data, end = \" \")\r\n            temp = temp.next\r\n\r\ndef deleteNode(head, key):\r\n        \r\n\r\n        if head == None:\r\n        \r\n            print(\"Element not present in the list\")\r\n            return\r\n\r\n        if head.data == key:\r\n        \r\n            temp = head\r\n            head = head.next\r\n            del temp\r\n            return \r\n\r\n        deleteNode(head.next, key)\r\n\r\n\r\n\r\n\r\nllist = LinkedList()\r\nllist.push(4)\r\nllist.push(3)\r\nllist.push(2)\r\nllist.push(1)\r\n\r\nprint (\"Created Linked List: \")\r\nllist.printList()\r\ndeleteNode(llist.head, 2)\r\nprint (\"&#92;nLinked List after Deletion of 2:\")\r\nllist.printList()\r\n\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\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_5291 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_5291 a\"),jQuery(\"#tab-content_5291\"));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<h4>Output<\/h4>\n<p>Created Linked List:<br \/>\n1 2 3 4 <\/p>\n<p>Linked List after Deletion of first occurance of node with value 2:<br \/>\n1 3 4 <\/p>\n<p><strong>Time Complexity:<\/strong> O(n), as list traversal is needed.<br \/>\n[forminator_quiz id=&#8221;5290&#8243;]<\/p>\n<p>So, in this article, we have tried our best to explain how to delete a node from a linked list. This is an important question when it comes to coding interviews.<br \/>\nIf 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 In this question, we are given a singly linked list and a value X. We have [&hellip;]<\/p>\n","protected":false},"author":52,"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":[125],"tags":[],"class_list":["post-5288","post","type-post","status-publish","format-standard","hentry","category-linked-list"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Linked List Deleting Node | Linked list articles | PrepBytes Blog<\/title>\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\/linked-list-deleting-node\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linked List Deleting Node | Linked list articles | PrepBytes Blog\" \/>\n<meta property=\"og:description\" content=\"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 In this question, we are given a singly linked list and a value X. We have [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/\" \/>\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-09-27T19:40:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-03-10T19:42:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007546200-Article_162.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=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Linked List Deleting Node\",\"datePublished\":\"2021-09-27T19:40:22+00:00\",\"dateModified\":\"2022-03-10T19:42:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/\"},\"wordCount\":904,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007546200-Article_162.png\",\"articleSection\":[\"Linked list articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/\",\"name\":\"Linked List Deleting Node | Linked list articles | PrepBytes Blog\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007546200-Article_162.png\",\"datePublished\":\"2021-09-27T19:40:22+00:00\",\"dateModified\":\"2022-03-10T19:42:20+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007546200-Article_162.png\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007546200-Article_162.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linked list articles\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/linked-list\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Linked List Deleting Node\"}]},{\"@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\/3f7dc4ae851791d5947a7f99df363d5e\",\"name\":\"Prepbytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"caption\":\"Prepbytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Linked List Deleting Node | Linked list articles | PrepBytes Blog","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\/linked-list-deleting-node\/","og_locale":"en_US","og_type":"article","og_title":"Linked List Deleting Node | Linked list articles | PrepBytes Blog","og_description":"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 In this question, we are given a singly linked list and a value X. We have [&hellip;]","og_url":"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2021-09-27T19:40:22+00:00","article_modified_time":"2022-03-10T19:42:20+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007546200-Article_162.png","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Linked List Deleting Node","datePublished":"2021-09-27T19:40:22+00:00","dateModified":"2022-03-10T19:42:20+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/"},"wordCount":904,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007546200-Article_162.png","articleSection":["Linked list articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/","url":"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/","name":"Linked List Deleting Node | Linked list articles | PrepBytes Blog","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007546200-Article_162.png","datePublished":"2021-09-27T19:40:22+00:00","dateModified":"2022-03-10T19:42:20+00:00","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007546200-Article_162.png","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007546200-Article_162.png"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/linked-list-deleting-node\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"Linked list articles","item":"https:\/\/prepbytes.com\/blog\/category\/linked-list\/"},{"@type":"ListItem","position":3,"name":"Linked List Deleting Node"}]},{"@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\/3f7dc4ae851791d5947a7f99df363d5e","name":"Prepbytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","caption":"Prepbytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5288","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\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=5288"}],"version-history":[{"count":6,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5288\/revisions"}],"predecessor-version":[{"id":7965,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5288\/revisions\/7965"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=5288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=5288"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=5288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}