-
About Queues
Hello Guys,
I have some questions about Queues, their are pointers in queues eg.
"front" and "rear". front is a pointer which points to the 1st element of the queue and rear is a pointer which points to the last element or data inserted in the queue.
I am actually making a program on bank which has counters and also has tellers. The purpose of teller is to serve the customer at the counter.
I wanted to know that can I declare the front and rear pointers in the Queue program as :
"int *front" and "int *rear" ?
thanks
-
If they are indices into an array of values, no.
If you're making a queue with a (doubly?)linked list, yes.
-
thanks for your reply,
but do we have to use doubly linked list for such programs? will not singly linked list be useful in this case?
-
Sure, but you have to remember to remove from the 'head' of the list and put stuff in the other end.
But, if you need a double ended queue, it'd be a poor idea to use a singly linked list.
-
You can use a single linked list or an array (circular buffer) for queue. If it's a list, then head and tail are pointers, if it's an array, then head and tail are indices.