Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

problem in function for deleting a Node by taking Node's data.

$
0
0
Everything in this function works fine. That is if the value actually exists. If you input a value that is not in the list, and you run the program, it crashes. Can anyone help please?
void deltarget (int value)
{
    if (front == NULL && tail == NULL)
    {
        return;
    }
    else if (front -> next == NULL  && front -> prev == NULL)
        front = tail = NULL;
    else if (front -> item == value)
        {
        front -> next -> prev = NULL;
        front = front -> next;

        }
    else if (tail -> item == value)
    {
        tail -> prev -> next = NULL;
        tail = tail -> prev;
    }
    else
    {
        Node *temp = front;
        while(temp -> item != value && temp -> next != NULL)
        {
            temp = temp -> next;
        }
        temp -> next -> prev = temp -> prev;
        temp -> prev -> next = temp -> next;
        delete temp;
    }

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>