<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>doubly linked list program in c - Wikitechy</title>
	<atom:link href="https://www.wikitechy.com/interview-questions/tag/doubly-linked-list-program-in-c/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.wikitechy.com/interview-questions/tag/doubly-linked-list-program-in-c/</link>
	<description>Interview Questions</description>
	<lastBuildDate>Mon, 13 Sep 2021 07:18:43 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.wikitechy.com/interview-questions/wp-content/uploads/2025/10/cropped-wikitechy-icon-32x32.png</url>
	<title>doubly linked list program in c - Wikitechy</title>
	<link>https://www.wikitechy.com/interview-questions/tag/doubly-linked-list-program-in-c/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Write a function to Delete a node from Doubly Linked List ?</title>
		<link>https://www.wikitechy.com/interview-questions/data-structure/write-a-function-to-delete-a-node-from-doubly-linked-list/</link>
					<comments>https://www.wikitechy.com/interview-questions/data-structure/write-a-function-to-delete-a-node-from-doubly-linked-list/#respond</comments>
		
		<dc:creator><![CDATA[Editor]]></dc:creator>
		<pubDate>Tue, 13 Jul 2021 14:56:24 +0000</pubDate>
				<category><![CDATA[Data Structure]]></category>
		<category><![CDATA[Accenture interview questions and answers]]></category>
		<category><![CDATA[algorithm for insertion and deletion in doubly linked list]]></category>
		<category><![CDATA[Altimetrik India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[Applied Materials interview questions and answers]]></category>
		<category><![CDATA[Bharti Airtel interview questions and answers]]></category>
		<category><![CDATA[BMC Software interview questions and answers]]></category>
		<category><![CDATA[Capgemini interview questions and answers]]></category>
		<category><![CDATA[CASTING NETWORKS INDIA PVT LIMITED interview questions and answers]]></category>
		<category><![CDATA[CGI Group Inc interview questions and answers]]></category>
		<category><![CDATA[Chetu interview questions and answers]]></category>
		<category><![CDATA[Ciena Corporation interview questions and answers]]></category>
		<category><![CDATA[Collabera Te interview questions and answers]]></category>
		<category><![CDATA[delete a node from linked list in c]]></category>
		<category><![CDATA[delete all nodes in doubly linked list]]></category>
		<category><![CDATA[delete all nodes in doubly linked list c++]]></category>
		<category><![CDATA[delete at position in a doubly linked list]]></category>
		<category><![CDATA[delete last node in doubly linked list in c++]]></category>
		<category><![CDATA[delete last node in doubly linked list java]]></category>
		<category><![CDATA[delete node from doubly linked list c++]]></category>
		<category><![CDATA[delete node from doubly linked list java]]></category>
		<category><![CDATA[deletion in doubly linked list]]></category>
		<category><![CDATA[Dell International Services India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[doubly circular linked list in data structure]]></category>
		<category><![CDATA[doubly linked list]]></category>
		<category><![CDATA[doubly linked list c code]]></category>
		<category><![CDATA[doubly linked list deletion]]></category>
		<category><![CDATA[doubly linked list deletion program in cm]]></category>
		<category><![CDATA[doubly linked list example]]></category>
		<category><![CDATA[doubly linked list implementation]]></category>
		<category><![CDATA[doubly linked list implementation in c]]></category>
		<category><![CDATA[doubly linked list in c]]></category>
		<category><![CDATA[doubly linked list in data structure]]></category>
		<category><![CDATA[doubly linked list insertion and deletion]]></category>
		<category><![CDATA[doubly linked list java]]></category>
		<category><![CDATA[doubly linked list operations]]></category>
		<category><![CDATA[doubly linked list program in c]]></category>
		<category><![CDATA[doubly linked list program in data structure]]></category>
		<category><![CDATA[doubly linked list program in data structure using c]]></category>
		<category><![CDATA[Flipkart interview questions and answers]]></category>
		<category><![CDATA[geekyants interview questions and answers]]></category>
		<category><![CDATA[Genpact interview questions and answers]]></category>
		<category><![CDATA[Globallogic India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[IBM interview questions and answers]]></category>
		<category><![CDATA[Indecomm Global Services interview questions and answers]]></category>
		<category><![CDATA[insertion and deletion in doubly linked list in c]]></category>
		<category><![CDATA[lete a node from doubly linked list]]></category>
		<category><![CDATA[Mphasis interview questions and answers]]></category>
		<category><![CDATA[NetApp interview questions and answers]]></category>
		<category><![CDATA[Oracle Corporation interview questions and answers]]></category>
		<category><![CDATA[remove node from doubly linked list java]]></category>
		<category><![CDATA[SAP Labs India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[Sapient Consulting Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[Tech Mahindra interview questions and answers]]></category>
		<category><![CDATA[Tracxn Technologies Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[UnitedHealth Group interview questions and answers]]></category>
		<category><![CDATA[Wipro Infotech interview questions and answers]]></category>
		<category><![CDATA[WM Global Technology Services India Pvt.Ltd Limited (WMGTS) interview questions and answers]]></category>
		<category><![CDATA[write a function to delete a node from doubly linked list]]></category>
		<category><![CDATA[write a function to delete a node from doubly linked list java]]></category>
		<category><![CDATA[Xoriant Solutions Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[Yodlee Infotech Pvt Ltd interview questions and answers]]></category>
		<guid isPermaLink="false">https://www.wikitechy.com/interview-questions/?p=485</guid>

					<description><![CDATA[Answer : In a single linked list, every node has link to its next node in the sequence...]]></description>
										<content:encoded><![CDATA[<div class="TextHeading">
<div class="hddn">
<h2 id="write-a-function-to-delete-a-node-from-doubly-linked-list" class="color-pink" style="text-align: justify;">Write a function to Delete a node from Doubly Linked List ?</h2>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>In a <a href="https://www.wikitechy.com/technology/insertion-sort-singly-linked-list/" target="_blank" rel="noopener">single linked list</a>, every node has link to its next node in the sequence.</li>
<li>So, we can traverse from one node to another node only in one direction and we cannot traverse back. We can solve this kind of problem by using <a href="https://www.wikitechy.com/technology/quicksort-doubly-linked-list-3/" target="_blank" rel="noopener">double linked list</a>.</li>
<li>Double linked list is a sequence of elements in which every element has links to its previous element and next element in the sequence.</li>
<li>In double linked list, every node has link to its previous node and next node. So, we can <a href="https://www.wikitechy.com/technology/java-program-inorder-tree-traversal-without-recursion/" target="_blank" rel="noopener">traverse</a> forward by using next field and can traverse backward by using previous field.</li>
</ul>
</div>
</div>
<div class="ImageContent">
<div class="hddn"><img decoding="async" class="img-responsive center-block aligncenter" src="https://cdn.wikitechy.com/interview-questions/data-structure/delete-a-node-from-doubly-linked-list.png" alt=" Delete a node Doubly Linked List" /></div>
<div>
<h2 id="algorithm" class="color-green" style="text-align: justify;">Algorithm</h2>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-markdown code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-markdown code-embed-code">Algorithm to delete node from any position<br/>Input :<br/> head <br/> {<br/>   Pointer to the first node of the list<br/> }<br/>last <br/> {<br/>   Pointer to the last node of the list<br/> }<br/>N <br/> {<br/>  Position to be deleted from list<br/> }<br/>Begin :<br/>    current ← head;<br/>    For i ← 1 to N and current != NULL do<br/>        current ← current.next;<br/>    End for<br/>    If (N == 1) then<br/>        deleteFromBeginning()<br/>    End if<br/>    Else if (current == last) then <br/>        deleteFromEnd()<br/>    End if<br/>    Else if (current != NULL) then<br/>        current.prev.next ← current.next<br/>        If (current.next != NULL) then<br/>            current.next.prev ← current.prev;<br/>        End if<br/>        unalloc (current)<br/>        write (&#039;Node deleted successfully from &#039;, N, &#039; position&#039;)<br/>    End if<br/>    Else then<br/>        write (&#039;Invalid position&#039;)<br/>    End if<br/>End</code></pre> </div>
<h2 id="sample-code-in-c" class="color-blue" style="text-align: justify;">Sample Code in C++</h2>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-markdown code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-markdown code-embed-code">#include &lt;bits/stdc++.h&gt; <br/>  <br/>using namespace std; <br/>  <br/>struct Node { <br/>    int data; <br/>    struct Node* next; <br/>    struct Node* prev; <br/>}; <br/>  <br/>/* Function to delete a node in a Doubly Linked List. <br/>   head_ref --&gt; pointer to head node pointer. <br/>   del  --&gt;  pointer to node to be deleted. */<br/>void deleteNode(struct Node** head_ref, struct Node* del) <br/>{ <br/>   <br/>    if (*head_ref == NULL || del == NULL) <br/>        return; <br/>  <br/>    /* If node to be deleted is head node */<br/>    if (*head_ref == del) <br/>        *head_ref = del-&gt;next; <br/>  <br/>    /* Change next only if node to be deleted is NOT  <br/>       the last node */<br/>    if (del-&gt;next != NULL) <br/>        del-&gt;next-&gt;prev = del-&gt;prev; <br/>  <br/>    /* Change prev only if node to be deleted is NOT  <br/>       the first node */<br/>    if (del-&gt;prev != NULL) <br/>        del-&gt;prev-&gt;next = del-&gt;next; <br/>  <br/>    /* Finally, free the memory occupied by del*/<br/>    free(del); <br/>} <br/>  <br/>/* Function to delete the node at the given position <br/>   in the doubly linked list */<br/>void deleteNodeAtGivenPos(struct Node** head_ref, int n) <br/>{ <br/>    /* if list in NULL or invalid position is given */<br/>    if (*head_ref == NULL || n &lt;= 0) <br/>        return; <br/>  <br/>    struct Node* current = *head_ref; <br/>    int i; <br/>  <br/>    /* traverse up to the node at position &#039;n&#039; from <br/>       the beginning */<br/>    for (int i = 1; current != NULL &amp;&amp; i &lt; n; i++) <br/>        current = current-&gt;next; <br/>  <br/>    /* if &#039;n&#039; is greater than the number of nodes <br/>       in the doubly linked list */<br/>    if (current == NULL) <br/>        return; <br/>  <br/>    /* delete the node pointed to by &#039;current&#039; */<br/>    deleteNode(head_ref, current); <br/>} <br/>  <br/>/* Function to insert a node at the beginning  <br/>   of the Doubly Linked List */<br/>void push(struct Node** head_ref, int new_data) <br/>{ <br/>    /* allocate node */<br/>    struct Node* new_node =  <br/>         (struct Node*)malloc(sizeof(struct Node)); <br/>  <br/>    /* put in the data  */<br/>    new_node-&gt;data = new_data; <br/>  <br/>    /* since we are adding at the beginning, <br/>    prev is always NULL */<br/>    new_node-&gt;prev = NULL; <br/>  <br/>    /* link the old list off the new node */<br/>    new_node-&gt;next = (*head_ref); <br/>  <br/>    /* change prev of head node to new node */<br/>    if ((*head_ref) != NULL) <br/>        (*head_ref)-&gt;prev = new_node; <br/>  <br/>    /* move the head to point to the new node */<br/>    (*head_ref) = new_node; <br/>} <br/>  <br/>/* Function to print nodes in a given doubly <br/>   linked list */<br/>void printList(struct Node* head) <br/>{ <br/>    while (head != NULL) { <br/>        cout &lt;&lt; head-&gt;data &lt;&lt; &quot; &quot;; <br/>        head = head-&gt;next; <br/>    } <br/>} <br/>  <br/>/* Driver program to test above functions*/<br/>int main() <br/>{ <br/>    /* Start with the empty list */<br/>    struct Node* head = NULL; <br/>  <br/>    /* Create the doubly linked list 10&lt;-&gt;8&lt;-&gt;4&lt;-&gt;2&lt;-&gt;5 */<br/>    push(&amp;head, 5); <br/>    push(&amp;head, 2); <br/>    push(&amp;head, 4); <br/>    push(&amp;head, 8); <br/>    push(&amp;head, 10); <br/>  <br/>    cout &lt;&lt; &quot;Doubly linked list before deletion:n&quot;; <br/>    printList(head); <br/>  <br/>    int n = 2; <br/>  <br/>    /* delete node at the given position &#039;n&#039; */<br/>    deleteNodeAtGivenPos(&amp;head, n); <br/>  <br/>    cout &lt;&lt; &quot;\nDoubly linked list after deletion:n&quot;; <br/>    printList(head); <br/>  <br/>    return 0; <br/>} </code></pre> </div>
<h2 id="output" class="color-purple" style="text-align: justify;">Output</h2>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-markdown code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-markdown code-embed-code">Doubly linked list before deletion:<br/>10 8 4 2 5<br/>Doubly linked list after deletion:<br/>10 4 2 5</code></pre> </div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="time-complexity" class="color-green">Time Complexity</h2>
</div>
</div>
<div class="Content">
<div class="hddn">
<ul>
<li style="text-align: justify;">O(n), in worst case where n is the number of nodes in the doubly linked list.</li>
</ul>
</div>
</div>
</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.wikitechy.com/interview-questions/data-structure/write-a-function-to-delete-a-node-from-doubly-linked-list/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
