<?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>delete first node in linked list c++ - Wikitechy</title>
	<atom:link href="https://www.wikitechy.com/interview-questions/tag/delete-first-node-in-linked-list-c/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.wikitechy.com/interview-questions/tag/delete-first-node-in-linked-list-c/</link>
	<description>Interview Questions</description>
	<lastBuildDate>Mon, 13 Sep 2021 06:50:32 +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>delete first node in linked list c++ - Wikitechy</title>
	<link>https://www.wikitechy.com/interview-questions/tag/delete-first-node-in-linked-list-c/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Delete all occurrences of a given key in a linked list ?</title>
		<link>https://www.wikitechy.com/interview-questions/data-structure/delete-all-occurrences-of-a-given-key-in-a-linked-list/</link>
					<comments>https://www.wikitechy.com/interview-questions/data-structure/delete-all-occurrences-of-a-given-key-in-a-linked-list/#respond</comments>
		
		<dc:creator><![CDATA[Editor]]></dc:creator>
		<pubDate>Tue, 13 Jul 2021 17:39:53 +0000</pubDate>
				<category><![CDATA[Data Structure]]></category>
		<category><![CDATA[Accenture interview questions and answers]]></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[c program to delete first node in linked list]]></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 specific node in linked list java]]></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 first node in linked list c++]]></category>
		<category><![CDATA[delete last node in doubly linked list in c++]]></category>
		<category><![CDATA[delete last node in linked list c++]]></category>
		<category><![CDATA[delete last node in linked list in c]]></category>
		<category><![CDATA[delete node at given position in a linked list in c++]]></category>
		<category><![CDATA[delete node from doubly linked list java]]></category>
		<category><![CDATA[Dell International Services India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[doubly linked list geeksforgeeks]]></category>
		<category><![CDATA[Flipkart 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[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 element from doubly linked list c++]]></category>
		<category><![CDATA[samsung interview questions and answers]]></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 program to delete a node from linked list in c++]]></category>
		<category><![CDATA[write ac program to delete a particular element in the doubly linked list]]></category>
		<category><![CDATA[write an algorithm to delete duplicate elements in a singly linked list]]></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=509</guid>

					<description><![CDATA[Answer : Given a singly linked list, delete all occurrences...]]></description>
										<content:encoded><![CDATA[<div class="TextHeading">
<div class="hddn">
<h2 id="delete-all-occurrences-of-a-given-key-in-a-linked-list" class="color-pink">Delete all occurrences of a given key in a linked list ?</h2>
</div>
</div>
<div class="CodeContent">
<div class="hddn">
<ul>
<li>Given a singly linked list, delete all occurrences of a given key in it. For example,</li>
</ul>
<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">Input:  2 -&gt; 1 -&gt; 8 -&gt; 2 -&gt;  3 -&gt;  2 -&gt; 7<br/>       Key to delete = 2<br/>Output:  1 -&gt; 8 -&gt; 3 -&gt; 7 </code></pre> </div>
<h2 id="sample-code-in-c" class="color-purple">Sample Code in C</h2>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-c code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-c code-embed-code">#include &lt;stdio.h&gt; <br/>#include &lt;stdlib.h&gt; <br/>// A linked list node <br/>struct Node <br/>{ <br/>    int data; <br/>    struct Node *next; <br/>}; <br/>/* Given a reference (pointer to pointer) to the head of a list <br/>   and an int, inserts a new node on the front of the list. */<br/>void push(struct Node** head_ref, int new_data) <br/>{ <br/>    struct Node* new_node = (struct Node*) malloc(sizeof(struct Node)); <br/>    new_node-&gt;data  = new_data; <br/>    new_node-&gt;next = (*head_ref); <br/>    (*head_ref)    = new_node; <br/>} <br/>/* Given a reference (pointer to pointer) to the head of a list and <br/>   a key, deletes all occurrence of the given key in linked list */<br/>void deleteKey(struct Node **head_ref, int key) <br/>{ <br/>    // Store head node <br/>    struct Node* temp = *head_ref, *prev; <br/>    // If head node itself holds the key or multiple occurrences of key <br/>    while (temp != NULL &amp;&amp; temp-&gt;data == key) <br/>    { <br/>        *head_ref = temp-&gt;next;   // Changed head <br/>        free(temp);               // free old head <br/>        temp = *head_ref;         // Change Temp <br/>    } <br/>    // Delete occurrences other than head <br/>    while (temp != NULL) <br/>    { <br/>        // Search for the key to be deleted, keep track of the <br/>        // previous node as we need to change &#039;prev-&gt;next&#039; <br/>        while (temp != NULL &amp;&amp; temp-&gt;data != key) <br/>        { <br/>            prev = temp; <br/>            temp = temp-&gt;next; <br/>        } <br/>        // If key was not present in linked list <br/>        if (temp == NULL) return; <br/>        // Unlink the node from linked list <br/>        prev-&gt;next = temp-&gt;next; <br/>        free(temp);  // Free memory <br/>        //Update Temp for next iteration of outer loop <br/>        temp = prev-&gt;next; <br/>    } <br/>} <br/>// This function prints contents of linked list starting from <br/>// the given node <br/>void printList(struct Node *node) <br/>{ <br/>    while (node != NULL) <br/>    { <br/>        printf(&quot; %d &quot;, node-&gt;data); <br/>        node = node-&gt;next; <br/>    } <br/>} <br/>   /* Drier program to test above functions*/<br/>int main() <br/>{ <br/>    /* Start with the empty list */<br/>    struct Node* head = NULL; <br/>    push(&amp;head, 7); <br/>    push(&amp;head, 2); <br/>    push(&amp;head, 3); <br/>    push(&amp;head, 2); <br/>    push(&amp;head, 8); <br/>    push(&amp;head, 1); <br/>    push(&amp;head, 2); <br/>    push(&amp;head, 2); <br/>    int key = 2; // key to delete <br/>    puts(&quot;Created Linked List: &quot;); <br/>    printList(head); <br/>    deleteKey(&amp;head, key); <br/>    puts(&quot;\nLinked List after Deletion: &quot;); <br/>    printList(head); <br/>    return 0; <br/>}</code></pre> </div>
<div class="TextHeading">
<div class="hddn">
<h2 id="output" class="color-purple">Output</h2>
</div>
</div>
<div class="Output">
<div class="hddn">
<figure class="highlight">
<pre><code class="hljs" data-lang=""><span class="nt">Created Linked List:
 2  2  1  8  2  3  2  7
Linked List after Deletion:
 1  8  3  7 </span></code></pre>
</figure>
</div>
</div>
</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.wikitechy.com/interview-questions/data-structure/delete-all-occurrences-of-a-given-key-in-a-linked-list/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to delete an element in a linked list ?</title>
		<link>https://www.wikitechy.com/interview-questions/data-structure/how-to-delete-an-element-in-a-linked-list/</link>
					<comments>https://www.wikitechy.com/interview-questions/data-structure/how-to-delete-an-element-in-a-linked-list/#respond</comments>
		
		<dc:creator><![CDATA[Editor]]></dc:creator>
		<pubDate>Tue, 13 Jul 2021 16:57:20 +0000</pubDate>
				<category><![CDATA[Data Structure]]></category>
		<category><![CDATA[Accenture interview questions and answers]]></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[c program to delete first node in linked list]]></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[compro technologies interview questions and answers]]></category>
		<category><![CDATA[delete a node from linked list algorithm]]></category>
		<category><![CDATA[delete a node in linked list with single pointer]]></category>
		<category><![CDATA[delete a specific node in linked list c++]]></category>
		<category><![CDATA[delete first node in linked list c++]]></category>
		<category><![CDATA[delete node at given position in a linked list]]></category>
		<category><![CDATA[delete node at given position in a linked list c++]]></category>
		<category><![CDATA[delete node at given position in a linked list in c++]]></category>
		<category><![CDATA[delete node linked list c++]]></category>
		<category><![CDATA[deletion in linked list in data structure]]></category>
		<category><![CDATA[Dell International Services India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[Flipkart 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[linked list delete node c++]]></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 element from linked list c++]]></category>
		<category><![CDATA[remove middle element linked list c++]]></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[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=499</guid>

					<description><![CDATA[Answer : To delete a node from linked list....]]></description>
										<content:encoded><![CDATA[<div class="TextHeading">
<div class="hddn">
<h2 id="how-to-delete-an-element-in-a-linked-list" class="color-pink" style="text-align: justify;">How to delete an element in a linked list ?</h2>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>To delete a node from <a href="https://www.wikitechy.com/tutorials/java/java-linked-list" target="_blank" rel="noopener">linked list</a>, we need to do following steps:
<ul>
<li>Find previous node of the node to be deleted.</li>
<li>Change the next of previous node.</li>
<li>Free memory for the node to be deleted</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="ImageContent" style="text-align: justify;">
<div class="hddn"><img decoding="async" class="img-responsive center-block aligncenter" src="https://cdn.wikitechy.com/interview-questions/data-structure/linkedlist-deletion.png" alt=" " /></div>
</div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="example" class="color-purple">Example</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">Input: position = 1, Linked List = 9-&gt;2-&gt;3-&gt;7-&gt;6<br/>Output: Linked List =  9-&gt;3-&gt;7-&gt;6<br/><br/>Input: position = 0, Linked List = 9-&gt;2-&gt;3-&gt;7-&gt;6<br/>Output: Linked List = 2-&gt;3-&gt;7-&gt;6</code></pre> </div>
<h2 id="sample-code" class="color-purple">Sample code</h2>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-java code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-java code-embed-code">#include &lt;stdio.h&gt; <br/>#include &lt;stdlib.h&gt; <br/><br/>// A linked list node <br/>struct Node <br/>{ <br/>	int data; <br/>	struct Node *next; <br/>}; <br/><br/>/* Given a reference (pointer to pointer) to the head of a list <br/>and an int, inserts a new node on the front of the list. */<br/>void push(struct Node** head_ref, int new_data) <br/>{ <br/>	struct Node* new_node = (struct Node*) malloc(sizeof(struct Node)); <br/>	new_node-&gt;data = new_data; <br/>	new_node-&gt;next = (*head_ref); <br/>	(*head_ref) = new_node; <br/>} <br/><br/>/* Given a reference (pointer to pointer) to the head of a list <br/>and a position, deletes the node at the given position */<br/>void deleteNode(struct Node **head_ref, int position) <br/>{ <br/>// If linked list is empty <br/>if (*head_ref == NULL) <br/>	return; <br/><br/>// Store head node <br/>struct Node* temp = *head_ref; <br/><br/>	// If head needs to be removed <br/>	if (position == 0) <br/>	{ <br/>		*head_ref = temp-&gt;next; // Change head <br/>		free(temp);			 // free old head <br/>		return; <br/>	} <br/><br/>	// Find previous node of the node to be deleted <br/>	for (int i=0; temp!=NULL &amp;&amp; i&lt;position-1; i++) <br/>		temp = temp-&gt;next; <br/><br/>	// If position is more than number of ndoes <br/>	if (temp == NULL || temp-&gt;next == NULL) <br/>		return; <br/><br/>	// Node temp-&gt;next is the node to be deleted <br/>	// Store pointer to the next of node to be deleted <br/>	struct Node *next = temp-&gt;next-&gt;next; <br/><br/>	// Unlink the node from linked list <br/>	free(temp-&gt;next); // Free memory <br/><br/>	temp-&gt;next = next; // Unlink the deleted node from list <br/>} <br/><br/>// This function prints contents of linked list starting from <br/>// the given node <br/>void printList(struct Node *node) <br/>{ <br/>	while (node != NULL) <br/>	{ <br/>		printf(&quot; %d &quot;, node-&gt;data); <br/>		node = node-&gt;next; <br/>	} <br/>} <br/><br/>/* Drier program to test above functions*/<br/>int main() <br/>{ <br/>	/* Start with the empty list */<br/>	struct Node* head = NULL; <br/><br/>	push(&amp;head, 6); <br/>	push(&amp;head, 7); <br/>	push(&amp;head, 3); <br/>	push(&amp;head, 2); <br/>	push(&amp;head, 9); <br/><br/>	puts(&quot;Created Linked List: &quot;); <br/>	printList(head); <br/>	deleteNode(&amp;head, 4); <br/>	puts(&quot;\nLinked List after Deletion at position 4: &quot;); <br/>	printList(head); <br/>	return 0; <br/>}</code></pre> </div>
<h2 id="output" class="color-purple">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">Created Linked List: <br/> 9  2  3  7  6 <br/>Linked List after Deletion at position 4: <br/> 9  2  3  7</code></pre> </div>
</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.wikitechy.com/interview-questions/data-structure/how-to-delete-an-element-in-a-linked-list/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
