File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Convert Queue Dequeue to Link list format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Convert Queue Dequeue to Link list format" Watch "Convert Queue Dequeue to Link list format" New topic
Author

Convert Queue Dequeue to Link list format

Jeremy Tan
Greenhorn

Joined: Feb 10, 2012
Posts: 2
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?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
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

Joined: Feb 10, 2012
Posts: 2
Is this what you are looking for?







Here you go.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Convert Queue Dequeue to Link list format