• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Convert Queue Dequeue to Link list format

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I'm new to data structures and I just bought a book in Amazon called Object-Oriented Data Structures Using Java by Nell Dale to accompany the required book my professor gave to us. We just recently covered linklist, and I'm trying to convert some of the examples in the book. One particular question I'm stuck with is converting the War game's queue dequeue class into a custom made linklist.

Here is the example code I got from the authors website:

War Game pp:


I'm not also sure how to convert ArrayBoundQueues and Bounded queue interface into link list. Any idea or example to help me jup start this problem?
 
Marshal
Posts: 79178
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are they interfaces? Do you mean ArrayBlockingQueue? That is a class which implements the Queue interface and also can block a thread so as to help with the producre-consumer problem, which you can find about by googling.
A linked list can implement Queue, too, but it does not normally block threads awaiting the availability of objects.
I think they have their own classes, which you would have to find the details of from their website or API documentation. We can’t help any more without that information.
 
Jeremy Tan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this what you are looking for?







Here you go.
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is a common-or-garden queue based on a circular array. A circular array is not one that joins up with itself, but one where you go back to the beginning from the end. You can tell that from the use of the % operator.
It would be quite easy to build a queue atop a linked list, which would have identical functionality, except that there is no limit to the size of your queue. You would still have to throw Exceptions if the queue is empty.
To enqueue something, add it at the beginning of your linked list, and to dequeue something, remove the last item in the list.
I presume you know how to build your own linked list?
reply
    Bookmark Topic Watch Topic
  • New Topic