This is the code for deleting the front item from the queue I have already made. I try to understand that itemPtr will be used somehow in main.. not known yet but that's not the point. I wonder whether
if (queue->count == 0)
can be used instead of
if (!queue->count)
Are the NULL and 0 used in the same way?
To add, what does this do?
free(deleteLoc)
I thought deleteLoc will disappear after this dequeue method ends but why add this? This is not my code so I'm curious. Does it obliterate the memory that deleteLoc contained or queue->front ? Isn't the point is to make the data itself be disappeared?
Thank you.
bool dequeue(H* queue ,void* itemPtr)
{
node* deletecLoc;
if (!queue->count)
return false;
*itemPtr = queue->front->dataPtr;
deleteLoc = queue->front;
if (queue->count == 1)
queue->front = queue->rear = NULL;
else
queue->front = queue->front->next;
(queue->count)--;
free(deleteLoc);
return true;
}