aspose file tools*
The moose likes JNLP and Web Start and the fly likes How to delete an element from the queue efficiently Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JNLP and Web Start
Bookmark "How to delete an element from the queue efficiently" Watch "How to delete an element from the queue efficiently" New topic
Author

How to delete an element from the queue efficiently

Veerabhadraiah As
Greenhorn

Joined: Dec 05, 2011
Posts: 3
Hello there,

have a basic problem regarding queue. I am trying to implement Queue in Java using integer array. Normally what we when removing an element from the front of the queue, we will simply increment the front value by one so that the front pointer will point to next location.


But what my worry is, lets say i have int array of size 10. I will insert 10 elements to this queue, delete 8 elements from the queue. so my from will now be pointing at location 8 and rear at 9. so my queue can now hold only 2 elements???!!! Its crazy.

I even tried keeping the front pointer pointing always at the 0th location and shift all the elements to left after deleting the element at the front. This works but what about the efficiency when i have say 1 million elements?

Is there any better way to handle this case?

Hope you guys understood my problem, am waiting for your valuable solutions..

thanks in advance
 
Consider Paul's rocket mass heater.
 
subject: How to delete an element from the queue efficiently