• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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: 79965
396
  • 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: 79965
396
  • 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?
 
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic