You are in fact appropriately setting head
to the next item in the queue and deleting the old head. However, for what appears to be no reason, you are using malloc()
to create memory which you then lose the only pointer to when you overwrite temp
on the next line. You should initialize temp
to head
. There is no need to malloc()
memory in a delete()
function. If you did need malloc()
, note that * 1
is redundant and unnecessary.
Also, what will happen if your queue is empty and head
is NULL
? Think about that.
Whether your queue will work or not remains to be seen since you will also need a tail
pointer to know where to add new items to the queue.
Additionally, I would avoid naming functions delete()
since it may be confused for the C++ keyword delete
. remove()
would be more appropriate.