Queue

When Java 6 was introduced, it was Sun's recommendation to use the Deque (pronounced "deck") for all Stack and Queue implemenations, which combines both in one collection class containing the familiar Stack and Queue methods, and to deprecate the legacy Stack and Queue classes from Java 5. JavaTools implements the Stack and Queue with the Deque.

In JavaTools a queue can simply be created with JDeque[]. It then has to be filled with elements afterwards.

"queue_1.gif"

"queue_2.gif"

However, it's also possible to create a new queue and supply initial values during creation:

"queue_3.gif"

"queue_4.gif"

JDequeSize[] returns the number of elements in the queue, and JDequeIsEmpty[] shows if the queue is empty:

"queue_5.gif"

"queue_6.gif"

"queue_7.gif"

"queue_8.gif"

A new element is added at the end of the queue with JDequeOffer[]or JDequeAdd[]:

"queue_9.gif"

"queue_10.gif"

The whole list of elements in the queue can be shown with JDequeElemsnts[]:

"queue_11.gif"

"queue_12.gif"

The type of elements that can be put in a queue can be anything: Integer, Real, String, or even List:

"queue_13.gif"

"queue_14.gif"

"queue_15.gif"

"queue_16.gif"

"queue_17.gif"

"queue_18.gif"

"queue_19.gif"

"queue_20.gif"

"queue_21.gif"

"queue_22.gif"

JDequePeek[] retrieves, but does not remove the first element of the queue:

"queue_23.gif"

"queue_24.gif"

JDequeElement[] does the same as JDequePeek[], except it throws an exception if the queue is empty.

JQueuePoll[] retrieves and removes the first element of the queue:

"queue_25.gif"

"queue_26.gif"

"queue_27.gif"

"queue_28.gif"

JDequeRemove[] does the same as JDequePoll[] except it throws an exception if the queue is empty. JDequeRemove[<queue>,<element>] removes the SPECIFIED element from the queue, if present.

"queue_29.gif"

"queue_30.gif"

"queue_31.gif"

"queue_32.gif"

With JDequeContains[] we can see if the queue contains a particular element:

"queue_33.gif"

"queue_34.gif"

"queue_35.gif"

"queue_36.gif"

"queue_37.gif"

"queue_38.gif"

JDequeClear[] completely clears the entire queue, returning an empty queue.

"queue_39.gif"

"queue_40.gif"

"queue_41.gif"

"queue_42.gif"

"queue_43.gif"

"queue_44.gif"

"queue_45.gif"

"queue_46.gif"

"queue_47.gif"

"queue_48.gif"

"queue_49.gif"

"queue_50.gif"

"queue_51.gif"

Performance

Note the memory-footprint the JDeque[] has on the Mathematica system: Not a single byte of data is stored in the kernel:

"queue_52.gif"

"queue_53.gif"

"queue_54.gif"

"queue_55.gif"

"queue_56.gif"

"queue_57.gif"

"queue_58.gif"

Compare against storing eight million integers in the Mathematica kernel:

"queue_59.gif"

"queue_60.gif"

"queue_61.gif"

Spikey Created with Wolfram Mathematica 7.0