{"id":4193,"date":"2021-08-21T06:56:35","date_gmt":"2021-08-21T06:56:35","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=4193"},"modified":"2023-07-27T13:05:05","modified_gmt":"2023-07-27T13:05:05","slug":"delete-a-node-at-a-given-position","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/","title":{"rendered":"Delete a Node at a Given Position in Singly Linked List"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645186706301-delete%20a%20node_Artboard%203.png\" alt=\"\" \/><\/p>\n<p>In this blog we will see how to delete a node from the singly linked list before the specified position. Given a singly linked list and a specific position, we must delete a node in that position in a singly linked list. Linked lists are fundamental data structures used in computer science to store and manage collections of elements efficiently. They offer dynamic memory allocation and provide flexible means of adding, removing, and traversing elements. Two common variations of linked lists are singly linked lists and doubly linked lists, each with its unique features and use cases.<\/p>\n<h3>How to Delete a Node at a Given Position in a Singly Linked List<\/h3>\n<p>Let&#8217;s start with an example to better understand the problem statement.<br \/>\nSuppose the linked list is 1 \u2192 5 \u2192 2 \u2192 7 and the position given is 2. So, we have to delete the node present at the second position.<\/p>\n<p><strong>Note:<\/strong> We are using 0 based indexing in this problem.<\/p>\n<p>The node in the second position of the given linked list is 2. As a result, we must remove two items from the given list. The final linked list after deleting 2 will be: 1 \u2192 5 \u2192 7<\/p>\n<p><strong>Input :<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/Input.png\" alt=\"\" \/><\/p>\n<p><strong>Output :<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/Output.png\" alt=\"\" \/><\/p>\n<p><strong>Explanation:<\/strong> The node at the 2nd position has been deleted.<br \/>\nWhat approach should we take to this problem? What comes to mind first when we consider how to delete a node from a linked list at a given position? Attempt to obtain the position, correct?<br \/>\nYes, but with a slight modification.<br \/>\nTo delete a node, we must also have a pointer to its predecessor. This can be solved by traversing until the (position &#8211; 1)th node.<\/p>\n<p>Let&#8217;s take a look at the approach.<\/p>\n<h3>Approach on How to Delete a Node Before a Given Position in a Singly Linked List<\/h3>\n<p>First, let&#8217;s think in terms of how to delete a node from the linked list at a given position. <\/p>\n<p>Let the linked list be:<\/p>\n<p>1 \u2192 5 \u2192 2 \u2192 7.<\/p>\n<p>So, here, if we delete the node (2), we get :<\/p>\n<p>1 \u2192 5 \u2192 7.<\/p>\n<p>So, by deleting the node(2) we are making a connection between node(1) and node(5). That means the next of node(1) point to node(5).<\/p>\n<p><strong>Observation<\/strong><\/p>\n<ul>\n<li>If we take some more examples, we will notice that we need to access the previous and next node of the node that we need to delete.<\/li>\n<li>Say if the node to be deleted is target, its previous node is prev, and its next node is next1. So, to delete the target node from the linked list, we need to perform the following operations:<br \/>\n1) prev \u2192 next = next1.<br \/>\n2) And finally, free the target node.<\/li>\n<\/ul>\n<p>By doing this, we are removing the target node at the given position and changing the necessary links.<\/p>\n<p>There are a few corner cases. Try to think them out by taking a few examples. Everything is discussed in detail in the algorithm section delete a node from linked list at a given position.<\/p>\n<h3>Algorithm for How to Delete a Node Before a Given Position in a Singly Linked List<\/h3>\n<ul>\n<li>If the head is NULL, return.<\/li>\n<li>Create a node temp and make it point to the head.<\/li>\n<li>If the position is 0, it means that we have to delete the head of the list. We can easily do that by head = temp \u2192 next and free(temp). As temp was pointing to the head, we have incremented the head and freed temp.<\/li>\n<li>If the position is not 0, we will proceed. Now, we will write a loop with i = 0 to i &lt; (position -1). As we have discussed, to delete a node, we need a pointer to its previous node. So while traversing the loop, we will increment temp.<\/li>\n<li>Now, after the loop ends, if the temp is NULL or temp \u2192 next is NULL, we will simply return as the position is more than the number of nodes in the linked list.<\/li>\n<li>If the above condition fails, we will have temp pointing to the (position &#8211; 1)th node. Now, we simply have to change the required pointers.<\/li>\n<li>We will save the temp \u2192 next \u2192 next in a new node next1. Now, we will free temp \u2192 next, as it is the node at the given position. In the end, temp \u2192 next = next1. &#8211; In this way, there is no unnecessary memory leak and the node at the given position is getting deleted successfully.<\/li>\n<\/ul>\n<p>Now, as are having the idea for the algorithm to delete a node before specified position in singly linked list in C. Let\u2019s see the dry to understand more in depth to delete a node from linked list at a given position.<\/p>\n<h3>Dry Run on How to Delete a Node Before a Given Position in a Singly Linked List<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/Delete-a-node-at-a-given-position-1.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/Delete-a-node-at-a-given-position-2.png\" alt=\"\" \/><\/p>\n<h3>Code Implementation on How to Delete a Node at a Given Position in a Singly Linked List<\/h3>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_4194 {\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_4194 .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_4194 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_4194 .wpsm_nav-tabs > li.active > a, #tab_container_4194 .wpsm_nav-tabs > li.active > a:hover, #tab_container_4194 .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_4194 .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_4194 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_4194 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_4194 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_4194 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_4194 .wpsm_nav-tabs > li > a:hover , #tab_container_4194 .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_4194 .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_4194 .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_4194 .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_4194 .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_4194 .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_4194 .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_4194 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_4194 .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_4194 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_4194 .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_4194 .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_4194\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_4194\">\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_4194_1\" aria-controls=\"tabs_desc_4194_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_4194_2\" aria-controls=\"tabs_desc_4194_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_4194_3\" aria-controls=\"tabs_desc_4194_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_4194_4\" aria-controls=\"tabs_desc_4194_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_4194\">\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_4194_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\nvoid insert(int );\r\nvoid display_List();\r\nvoid delete(int );\r\n \r\nstruct node             \/\/ Structure declaration\r\n{\r\n    int data;\r\n    struct node *next;  \/\/ Self referral pointer\r\n}*head=NULL,*tail=NULL; \/\/ Initial value of Head and Tail pointer is NULL\r\n \r\n \r\nvoid delete(int pos)\r\n{\r\n    struct node *temp = head;       \/\/ Creating a temporary variable pointing to head\r\n    int i;                    \r\n    if(pos==0)\r\n    {\r\n        printf(&quot;&#92;nElement deleted is : %d&#92;n&quot;,temp-&gt;data);\r\n        head=head-&gt;next;        \/\/ Advancing the head pointer\r\n        temp-&gt;next=NULL;\r\n        free(temp);             \/\/ Node is deleted\r\n    }\r\n    else\r\n    {\r\n        for(i=0;i&lt;pos-1;i++) {=&quot;&quot; temp=&quot;temp-&quot;&gt;next;\r\n        }\r\n        \/\/ Now temp pointer points to the previous node of the node to be deleted\r\n        struct node *del =temp-&gt;next;       \/\/ del pointer points to the node to be deleted\r\n        temp-&gt;next=temp-&gt;next-&gt;next;\r\n        printf(&quot;&#92;nElement deleted is : %d&#92;n&quot;,del-&gt;data);      \r\n        del-&gt;next=NULL;\r\n        free(del);                          \/\/ Node is deleted\r\n    }\r\n    printf(&quot;&#92;nUpdated Linked List is : &#92;n&quot;);\r\n    display_List();\r\n    return ;\r\n}\r\n \r\n \r\n \r\nvoid insert(int value)\r\n{\r\n    struct node *newnode;  \/\/ Creating a new node\r\n    newnode = (struct node *)malloc(sizeof(struct node)); \/\/ Allocating dynamic memory\r\n \r\n    newnode-&gt;data = value;      \/\/ Assigning value to newnode\r\n    newnode-&gt;next = NULL;    \r\n \r\n    if(head==NULL)      \/\/ Checking if List is empty\r\n    {\r\n        head = newnode;\r\n        tail = newnode;\r\n    }\r\n    else                \/\/ If not empty then...\r\n    {\r\n        tail-&gt;next=newnode;    \r\n        tail=newnode;       \/\/ Updating the tail node with each insertion\r\n    }\r\n    return ;\r\n}\r\n \r\nvoid display_List()\r\n{\r\n    struct node *temp;    \/\/ Creating a temporary pointer to the structure\r\n    temp=head;          \/\/ temp points to head;\r\n    while(temp!=NULL)\r\n    {\r\n        if(temp-&gt;next==NULL)\r\n        {\r\n            printf(&quot; %d-&gt;NULL&quot;,temp-&gt;data);\r\n        }\r\n        else\r\n        {\r\n            printf(&quot; %d-&gt;&quot;,temp-&gt;data);\r\n        }\r\n        temp=temp-&gt;next;            \/\/ Traversing the List till end\r\n    }\r\n    printf(&quot;&#92;n&quot;);\r\n    return ;\r\n}\r\n\/\/ --Driver Code--\r\nint main()\r\n{\r\n    insert(1);\r\n    insert(2);\r\n    insert(3);\r\n    insert(4);\r\n    insert(5);\r\n    insert(6);\r\n    printf(&quot;&#92;n--Created Linked List--&#92;n&quot;);\r\n    display_List();\r\n    printf(&quot;&#92;nLinked List after deletion&quot;);\r\n    delete(2);                                   \/\/ List indexing starts from 0\r\n    return 0;\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_4194_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;iostream&gt;\r\nusing namespace std;\r\n\r\nclass Node\r\n{\r\n    public:\r\n    int data;\r\n    Node *next;\r\n};\r\n\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\nvoid deleteNode(Node **head_ref, int position)\r\n{\r\n\r\n    if (*head_ref == NULL)\r\n        return;\r\n\r\n    Node* temp = *head_ref;\r\n\r\n    if (position == 0)\r\n    {\r\n\r\n        *head_ref = temp-&gt;next;\r\n\r\n        free(temp);            \r\n        return;\r\n    }\r\n \r\n    for(int i = 0; temp != NULL &amp;&amp; i &lt; position - 1; i++)\r\n        temp = temp-&gt;next;\r\n\r\n    if (temp == NULL || temp-&gt;next == NULL)\r\n        return;\r\n\r\n     Node *next1 = temp-&gt;next-&gt;next;\r\n \r\n    \r\n    free(temp-&gt;next); \r\n\r\n    temp-&gt;next = next1;\r\n}\r\n\r\nvoid printList( 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\nint main()\r\n{\r\n\r\n    Node* head = NULL;\r\n \r\n    push(&amp;head, 7);\r\n    push(&amp;head, 2);\r\n    push(&amp;head, 5);\r\n    push(&amp;head, 1);\r\n \r\n    cout &lt;&lt; &quot;Created Linked List: &quot;;\r\n    printList(head);\r\n    deleteNode(&amp;head, 2);\r\n    cout &lt;&lt; &quot;&#92;nLinked List after Deletion at position 2: &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_4194_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{\r\n    Node head; \r\n    class Node\r\n    {\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    public void push(int new_data)\r\n    {\r\n\r\n        Node new_node = new Node(new_data);\r\n\r\n        new_node.next = head;\r\n\r\n        head = new_node;\r\n    }\r\n\r\n    void deleteNode(int position)\r\n    {\r\n\r\n        if (head == null)\r\n            return;\r\n\r\n        Node temp = head;\r\n\r\n        if (position == 0)\r\n        {\r\n            head = temp.next;  \r\n            return;\r\n        }\r\n\r\n        for (int i=0; temp!=null &amp;&amp; i&lt;position-1; i++)\r\n            temp = temp.next;\r\n\r\n        if (temp == null || temp.next == null)\r\n            return;\r\n\r\n        Node next1 = temp.next.next;\r\n \r\n        temp.next = next1;  \r\n    }\r\n\r\n    public void printList()\r\n    {\r\n        Node tnode = head;\r\n        while (tnode != null)\r\n        {\r\n            System.out.print(tnode.data+&quot; &quot;);\r\n            tnode = tnode.next;\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(7);\r\n        llist.push(2);\r\n        llist.push(5);\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        llist.deleteNode(2);  \r\n \r\n        System.out.println(&quot;&#92;nLinked List after Deletion at position 2: &quot;);\r\n        llist.printList();\r\n    }\r\n}\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_4194_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    def __init__(self, data):\r\n        self.data = data\r\n        self.next = None\r\n\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    def deleteNode(self, position):\r\n        if self.head is None:\r\n            return\r\n        if position == 0:\r\n            self.head = self.head.next\r\n            return self.head\r\n        index = 0\r\n        current = self.head\r\n        prev = self.head\r\n        temp = self.head\r\n        while current is not None:\r\n            if index == position:\r\n                temp = current.next\r\n                break\r\n            prev = current\r\n            current = current.next\r\n            index += 1\r\n        prev.next = temp\r\n        return prev\r\n\r\n    def printList(self):\r\n        temp = self.head\r\n        while(temp):\r\n            print (&quot; %d &quot; % (temp.data),end=&quot; &quot;)\r\n            temp = temp.next\r\n\r\nllist = LinkedList()\r\nllist.push(7)\r\nllist.push(2)\r\nllist.push(5)\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 at position 4: &quot;)\r\nllist.printList()\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_4194 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_4194 a\"),jQuery(\"#tab-content_4194\"));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><\/p>\n<pre><code>Created Linked List: 1 5 2 7\nLinked List after Deletion at position 2: 1 5 7<\/code><\/pre>\n<p><strong>Time Complexity:<\/strong> O(n), as list traversal is needed.<\/p>\n<p><strong>Conclusion<\/strong><br \/>\nIn conclusion, deleting a node from a linked list at a given position is a crucial operation in linked list manipulation, and understanding the process is essential for efficient data management in computer programming. Throughout this article, we explored the intricacies of linked lists, delving into node structures, pointer manipulations, and traversal techniques to effectively delete a node at a specified position.<\/p>\n<p>We learned that the delete operation involves careful handling of pointers to avoid memory leaks and maintain the integrity of the linked list. By following the step-by-step explanations and examples provided, readers can confidently implement the delete operation in various programming languages.<\/p>\n<h2>Frequently Asked Questions (FAQs) To Delete a Node Before Specified Position in Singly Linked List in C<\/h2>\n<p>Here are a few FAQs on how to delete a node from linked list at a given position.<\/p>\n<p><strong>1. Is it possible to delete a node from a linked list without traversing the list?<\/strong><br \/>\nNo, deleting a node from a linked list at a given position requires traversing the list to identify the target node and update the pointers.<\/p>\n<p><strong>2. What happens to the memory occupied by the deleted node in the linked list?<\/strong><br \/>\nThe memory occupied by the deleted node is deallocated and becomes available for other memory allocations in the program.<\/p>\n<p><strong>3. How can I delete a node at the beginning (head) of the linked list?<\/strong><br \/>\nTo delete the head node, update the head pointer to point to the next node in the list and free the memory of the original head node.<\/p>\n<p><strong>4. What happens if I try to delete a node from an empty linked list?<\/strong><br \/>\nDeleting a node from an empty linked list is not possible, and appropriate checks should be implemented to handle such scenarios.<\/p>\n<p><strong>5. Can I delete multiple occurrences of the same value in a linked list?<\/strong><br \/>\nYes, you can delete multiple occurrences of the same value by repeating the delete operation until all occurrences are removed.<\/p>\n<p><strong>6. How does the time complexity of the delete operation in a linked list compare to an array?<\/strong><br \/>\nThe time complexity of the delete operation in a linked list is O(n) in the worst case, while for an array, it is O(n) for linear search plus O(n) for element shifting, resulting in an overall complexity of O(n^2) in the worst case.<\/p>\n<p><strong>7. Can I delete a node at a negative position in the linked list?<\/strong><br \/>\nNo, the position must be a positive integer within the valid range of the linked list size.<\/p>\n<table width=\"641\">\n<tbody>\n<tr>\n<td colspan=\"2\" width=\"641\" style=\"text-align: center\"><strong>Related Articles<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/doubly-circular-linked-list-introduction-and-insertion\/\">Doubly circular linked list in data structure<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/advantages-disadvantages-and-uses-of-a-doubly-linked-list\/\">Application of doubly linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/applications-of-linked-list-data-structure\/\">Applications of linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/difference-between-a-singly-linked-list-and-a-doubly-linked-list\/\">Singly linked list vs doubly linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/advantage-and-disadvantage-of-linked-list-over-array\/\">Advantages and disadvantages of linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/menu-driven-program-for-all-operations-on-doubly-linked-list-in-c\/\">Doubly linked list all operations in C<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/binary-search\/binary-search-on-linked-list\/\">Binary search in linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/bubble-sort-for-linked-list-by-swapping-nodes\/\">Bubble sort linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/delete-a-node-in-doubly-linked-list\/\">Deletion in doubly linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/delete-middle-of-linked-list\/\">Delete the middle node of a linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/adding-two-polynomials-using-linked-list\/\">Polynomial addition using linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/find-the-smallest-and-largest-elements-in-a-singly-linked-list\/\">Find max value and min value in linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/insert-a-node-at-a-specific-position-in-a-linked-list\/\">Insert a node at a specific position in a linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/swap-nodes-in-a-linked-list-without-swapping-data\/\">Swap nodes in linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/add-two-numbers-represented-by-linked-lists-set-1\/\">Add two numbers represented by linked lists<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/find-the-first-node-of-the-loop-in-a-linked-list\/\">Find starting point of loop in linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/merge-sort-on-a-singly-linked-list\/\">Merge sort linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list-articles\/student-record-management-system-using-linked-list\/\">Student management system using linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/remove-duplicates-from-an-unsorted-linked-list\/\">Remove duplicates from unsorted linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/python\/python-program-to-reverse-a-linked-list\/\">Reverse a linked list in Python<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>In this blog we will see how to delete a node from the singly linked list before the specified position. Given a singly linked list and a specific position, we must delete a node in that position in a singly linked list. Linked lists are fundamental data structures used in computer science to store and [&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":[125],"tags":[],"class_list":["post-4193","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>Delete a Node at a Given Position in the Singly Linked List<\/title>\n<meta name=\"description\" content=\"Learn the most efficient way to delete a node at a given position in the linked list. Check the most efficient approach to delete a node at a given position.\" \/>\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\/delete-a-node-at-a-given-position\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Delete a Node at a Given Position in the Singly Linked List\" \/>\n<meta property=\"og:description\" content=\"Learn the most efficient way to delete a node at a given position in the linked list. Check the most efficient approach to delete a node at a given position.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/\" \/>\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-08-21T06:56:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-27T13:05:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645186706301-delete%20a%20node_Artboard%203.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=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/\"},\"author\":{\"name\":\"PrepBytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e\"},\"headline\":\"Delete a Node at a Given Position in Singly Linked List\",\"datePublished\":\"2021-08-21T06:56:35+00:00\",\"dateModified\":\"2023-07-27T13:05:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/\"},\"wordCount\":1350,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645186706301-delete%20a%20node_Artboard%203.png\",\"articleSection\":[\"Linked list articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/\",\"name\":\"Delete a Node at a Given Position in the Singly Linked List\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645186706301-delete%20a%20node_Artboard%203.png\",\"datePublished\":\"2021-08-21T06:56:35+00:00\",\"dateModified\":\"2023-07-27T13:05:05+00:00\",\"description\":\"Learn the most efficient way to delete a node at a given position in the linked list. Check the most efficient approach to delete a node at a given position.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645186706301-delete%20a%20node_Artboard%203.png\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645186706301-delete%20a%20node_Artboard%203.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/#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\":\"Delete a Node at a Given Position in Singly Linked List\"}]},{\"@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":"Delete a Node at a Given Position in the Singly Linked List","description":"Learn the most efficient way to delete a node at a given position in the linked list. Check the most efficient approach to delete a node at a given position.","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\/delete-a-node-at-a-given-position\/","og_locale":"en_US","og_type":"article","og_title":"Delete a Node at a Given Position in the Singly Linked List","og_description":"Learn the most efficient way to delete a node at a given position in the linked list. Check the most efficient approach to delete a node at a given position.","og_url":"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2021-08-21T06:56:35+00:00","article_modified_time":"2023-07-27T13:05:05+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645186706301-delete%20a%20node_Artboard%203.png","type":"","width":"","height":""}],"author":"PrepBytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"PrepBytes","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/"},"author":{"name":"PrepBytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e"},"headline":"Delete a Node at a Given Position in Singly Linked List","datePublished":"2021-08-21T06:56:35+00:00","dateModified":"2023-07-27T13:05:05+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/"},"wordCount":1350,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645186706301-delete%20a%20node_Artboard%203.png","articleSection":["Linked list articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/","url":"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/","name":"Delete a Node at a Given Position in the Singly Linked List","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645186706301-delete%20a%20node_Artboard%203.png","datePublished":"2021-08-21T06:56:35+00:00","dateModified":"2023-07-27T13:05:05+00:00","description":"Learn the most efficient way to delete a node at a given position in the linked list. Check the most efficient approach to delete a node at a given position.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645186706301-delete%20a%20node_Artboard%203.png","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645186706301-delete%20a%20node_Artboard%203.png"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/delete-a-node-at-a-given-position\/#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":"Delete a Node at a Given Position in Singly Linked List"}]},{"@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\/4193","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=4193"}],"version-history":[{"count":12,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/4193\/revisions"}],"predecessor-version":[{"id":17397,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/4193\/revisions\/17397"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=4193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=4193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=4193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}