From 1c1437588d7f2c12316483adf59525cb6d208f74 Mon Sep 17 00:00:00 2001
From: anshita2000 <44469617+anshita2000@users.noreply.github.com>
Date: Mon, 4 Oct 2021 10:54:31 +0530
Subject: [PATCH] Update deleteNode.cpp

---
 linked_list_problems/deleteNode.cpp | 45 +++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/linked_list_problems/deleteNode.cpp b/linked_list_problems/deleteNode.cpp
index c2a7b46..a64f9de 100644
--- a/linked_list_problems/deleteNode.cpp
+++ b/linked_list_problems/deleteNode.cpp
@@ -50,6 +50,51 @@ void deleteNode( Node * node )
   delete nextNode;
 }
 
+//Delete a Linked List node at a given position
+void deleteNode(Node **head_ref, int position)
+{
+     
+    // If linked list is empty
+    if (*head_ref == NULL)
+        return;
+     
+    // Store head node
+    Node* temp = *head_ref;
+ 
+    // If head needs to be removed
+    if (position == 0)
+    {
+         
+        // Change head
+        *head_ref = temp->next;
+         
+        // Free old head
+        free(temp);            
+        return;
+    }
+ 
+    // Find previous node of the node to be deleted
+    for(int i = 0; temp != NULL && i < position - 1; i++)
+        temp = temp->next;
+ 
+    // If position is more than number of nodes
+    if (temp == NULL || temp->next == NULL)
+        return;
+ 
+    // Node temp->next is the node to be deleted
+    // Store pointer to the next of node to be deleted
+     Node *next = temp->next->next;
+ 
+    // Unlink the node from linked list
+    free(temp->next); // Free memory
+     
+     
+    temp->next = next;
+}
+ 
+
+
+
 int main()
 {
   Node * head = nullptr;