Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Queue Implementation  RSS feed

 
Srini Swami
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Which is the best way (performance) to implement a queue (large and unbounded). I am working with Java 1.4, so no queue classes.

Right now, I am using LinkedList to implement the queue. Do containers add substantial overhead ? Are there any ways for non-container implementation ?

Thanks
Srini
 
Joe Ess
Bartender
Posts: 9429
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LinkedList IS a queue if you use addLast() and removeFirst().
As for "substantial" overhead, sure, there's some overhead in creating the nodes to wrap the data in the list, but in any non-trivial program the overhead would be ridiculously small.
As for making a non-container implementation, you can do it, but why would you want to? The code in the API is well-documented and well-tested. Anything you write would not be. When given the choice, stick to the API.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A circular buffer style implementation would involve less object creation than the LinkedList but you would have to live within the initial buffer size limitation.
Bill
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!