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?
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.
Joined: Feb 10, 2012
Is this what you are looking for?
Here you go.
Joined: Oct 13, 2005
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?