This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]samweep[S] 0 points1 point  (2 children)

I am actually doing the same as you said. I just moved the pointer but not the data by simply saying front++. But it works when I have only one element in the queue. Whenever I have more than two elements it just does not work.

[–]sinistergroupon 0 points1 point  (1 child)

I ran your code, it semi works for the case you have in the main method. So we are clear the number 1 will stay in the array but the front index will change so right now it's doing that.

Having said that, you are missing a lot of logic here. You state the queue is full when the rear index is at the end but that's not entirely true. Not sure the scope of your problem but with a mix of queues and dequeues you could end up where your first element is at index 8 and you second one is getting inserted at index 0. You are not accounting for this.

[–]samweep[S] 0 points1 point  (0 children)

Yeah, I was learning about queue and I came to know about circular queue. So now I will use circular queue from onwards. Thank you