I am trying to delete the first node in the singly link list but cant seem to do so? My Code is below... Could someone please suggest something.
thanks.
This program has an enqueue function which works.*p
is a pointer to a node which has been allocated using malloc.
The descriptions are given below for reference.
typedef struct Node
{
int element;
struct Node *next;
} Node;
typedef struct Queue
{
Node *front;
Node *rear;
} Queue;
Now this is the function I am having problems with.
int q_dequeue ( Queue *theQ, int *value)
{
Node *p;
if( theQ -> front == NULL)
{
printf ("Queue is empty. Cannot dequeue.\n");
return 0;
}
p = theQ -> front;
*value = p -> element;
if(theQ -> front != NULL && theQ -> rear == NULL)
{
theQ -> front = NULL;
theQ -> rear = NULL;
free(p);
}
else
{
theQ -> front = p -> next;
free(p);
}
return 1;
}