If you would use the debugger you would quickly see what's wrong. You should really get acquainted to use it.
What I can see in your code is that you don't update
front
and
rear
consequently. For example: What does
rear
point to in an empty queue? Probably NULL, I assume. So what happens in
Enqueue
when you are inserting the first element? You are using the
read
pointer (which is null) and do:
rear->Next = temp;
which will produce undefined results. Similarly in
Dequeue
: What happens when you remove the last element? In that case
front
and
rear
should be set to NULL. I don't see that in your code. So again you are provoking undefined behavior.