title: Deletion of specific node from singly Linked list with the help of data given
body: <p>I am trying to delete the node of specific data. For this, I am using deleteNode function but not able to delete. Please see the code:</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  
  class node
  {
      public:
      int data;
      node* next;
  
      ///constructor for initializing the data-
  
      node(int d)
      {
          data=d;
          next=NULL;
      }
  
  };
  void addAtEnd(node* &amp;head,int data)
  {
      if(head==NULL)
      {
          head=new node(data);
          return ;
      }
    node* temp=head;
    while(temp-&gt;next!=NULL)
    {
        temp=temp-&gt;next;
    }
    node* n =new node(data);
    n-&gt;data=data;
    temp-&gt;next=n;
    n-&gt;next=NULL;
    return;
  }
  AddAtTail(node* head,int d)
  {
    node* ptr=head;
    while(ptr-&gt;next!=NULL)
    {
        ptr=ptr-&gt;next;
    }
    node *n=new node(d);
    ptr-&gt;next=n;
    n-&gt;next=NULL;
  
  
  }
  AddAtPosition(node* head,int p,int d)
  {
  
      ///2 3 4 6 7 8 -1
      ///4th Position-
      node*ptr=head;
      int jump=1;
      while(jump&lt;=p-1)
      {
          jump++;
          ptr=ptr-&gt;next;
      }
      node*n=new node(d);
      n-&gt;next=ptr-&gt;next;
      ptr-&gt;next=n;
  
  
  }
  
  /// Delete First node
  void deleteFirst(node *&amp;head)
  {
      head=head-&gt;next;
  
  }
  
  ///Delete last node;
  void deleteLast(node* head)
  {
    node* ptr=head;
    while(ptr-&gt;next-&gt;next!=NULL)
    {
        ptr=ptr-&gt;next;
    }
    ptr-&gt;next=NULL;
  }
  **///Delete Specific Node  :-**
  </code></pre>
  
  <p>Here the function starts for deleting the node. I am trying to delete the node that has data 3 I am taking data as input from main function.</p>
  
  <pre><code>void deleteData(node* head,int d)
  {
      node*ptr=head;
      while(ptr-&gt;next!=NULL)
      {
         if(ptr-&gt;next-&gt;data==d)
         {
           ptr=ptr-&gt;next-&gt;next;
           return;
         }
         ptr=ptr-&gt;next;
      }
  }
  
  
  void takeInput(node*&amp; head)
  {
  
      int d;
      cin&gt;&gt;d;
      while(d!=-1)
      {
        addAtEnd(head,d);
        cin&gt;&gt;d;
  
      }
  }
  void print(node* head)
  {
      while(head!=NULL)
      {
          cout&lt;&lt;head-&gt;data&lt;&lt;"=&gt;";
          head=head-&gt;next;
      }
  }
  AddAtFront(node* &amp;head,int d)
  {
     ///create new node;
     node*n=new node(d);
     n-&gt;next=head;
     head=n;
  
  
  }
  
  int main()
  {
      node* head(NULL);
      takeInput(head);
      print(head);
      cout&lt;&lt;endl&lt;&lt;endl&lt;&lt;endl&lt;&lt;"---------- Here The Insertion Process starts at different Positions -----------"&lt;&lt;endl;
      cout&lt;&lt;endl&lt;&lt;"Adding at Tail"&lt;&lt;endl;
  
      AddAtTail(head,9);
      print(head);
      cout&lt;&lt;endl&lt;&lt;"Adding at Position p"&lt;&lt;endl;
      int p,d;
  
      cout&lt;&lt;"Enter Position and data :"&lt;&lt;endl;
      cin&gt;&gt;p&gt;&gt;d;
      AddAtPosition(head,p,d);
      print(head);
      cout&lt;&lt;endl&lt;&lt;"Adding at Front"&lt;&lt;endl;
      cout&lt;&lt;"Enter data to add at front : "&lt;&lt;endl;
      cin&gt;&gt;d;
      AddAtFront(head,d);
  
      print(head);
      cout&lt;&lt;endl&lt;&lt;endl&lt;&lt;endl;
      cout&lt;&lt;endl&lt;&lt;"--------------------  NOW LETS PERFORM DELETION  ------------------"&lt;&lt;endl;
      cout&lt;&lt;endl&lt;&lt;"Deleting first node :"&lt;&lt;endl;
      deleteFirst(head);
      print(head);
      cout&lt;&lt;endl;
      cout&lt;&lt;endl&lt;&lt;"Deleting Last node :"&lt;&lt;endl;
      deleteLast(head);
      print(head);
      cout&lt;&lt;endl;
      cout&lt;&lt;"deleting specific node"&lt;&lt;endl;
      cout&lt;&lt;"Enter data to delete"&lt;&lt;endl;
      cin&gt;&gt;d;
      deleteData(head,d);
      print(head);
      cout&lt;&lt;endl;
  
      return 0;
  }
  </code></pre>
  
  <p>Please see DeleteNode function in which I am trying to delete the node.
  Why node is not deleting? Here is the function:</p>
  
  <pre><code>**///Delete Specific Node i.e- data :-**
      void deleteData(node* head,int d)
      {
          node*ptr=head;
          while(ptr-&gt;next!=NULL)
          {
             if(ptr-&gt;next-&gt;data==d)
             {
               ptr=ptr-&gt;next-&gt;next;
               return;
             }
             ptr=ptr-&gt;next;
          }
      }
  </code></pre>
  
  <p>But Node is not deleting.</p>