When consistantly pushing to the top, this data structure acts as a stack. When consistantly pushing to the bottom, it acts as a queue. Sorting and inserting always put the low time value on top so that popping off the sorted queue or stack occurs in simulated time order.
One gotcha to watch out for is that the queue is not NULL terminated. In order to iterate through the queue, you need to first find out how many items are in the queue and then stop when that number is reached.
-
-
-
Method: clear
Summary: Clear this queue and delete all the items
Description: Sets top and bottom of this queue to NULL, and number of items
to zero
Return: None
-
Method: concat
Summary: Concatenate a specified queue with this queue, and reset the
specified (passed in) queue
Description:
Return: None
- q
- IN: specified queue to concatenate with this queue.
-
Method: copy
Summary: Copy this queue
Description:
Return: A copy of this queue
-
Overloaded Method: deque
Summary: Remove (but don't delete) an item from the queue
Description:
Return: None
- item
- IN: item to remove.
-
Overloaded Method: deque
Summary: Remove (but don't delete) an item from the queue
Description:
Return: A removed (but not deleted) item from the queue
- rid
- IN: ID of item to remove.
-
- Method: fast_pop_top Summary: Pops a specified item off of (ie, removes a specified item from) the top of the queue and returns it, but loses track of the number of items in the queue Description: This method has undefined (erroneous) behavior when the queue is empty or has only one item in it. It also does not decrement the number of items. If either of these issues are (or potentially are) a problem, use pop_top, which is a slower but safe routine, instead.
One reason you may use this method is that you want to quickly grab all the items off of a queue while emptying the queue. You could first find the number of items in the queue, use fast_pop_top() to get all the items and then call queue->init(NULL, NULL, 0) to set the number of items to zero. Be very careful in using this method!.
Return: Item that has been popped off of (removed from) the top of the queue.
-
Method: get_bot (same as pbot)
Summary: Get a pointer to the item at the bottom of the queue without
removing it from the queue.
Description:
Return: A pointer to the item at the bottom of the queue
-
Method: get_item
Summary: Get a pointer to the item with a specified ID
Description:
Return: A pointer to the item with a specified ID
- id
- IN: ID of item.
-
Method: get_length (same as length)
Summary: Get the number of items in the queue
Description: This method is perfect for finding out how many items
are in a queue before you start iterating through those
items.
Return: The number of items in the queue
-
Method: get_top (same as ptop)
Summary: Get a pointer to the item at the top of the queue without removing
it from the queue.
Description:
Return: A pointer to the item at the top of the queue
-
Method: init
Summary: Initialize the queue object
Description: This should be called initially or just after clearing
the queue. Otherwise, calling this method will
permanently lose the current information in the queue
and create memory leaks.
Return: None
- t
- IN: top of the queue.
- b
- IN: bottom of the queue.
- len
- IN: number of items in the queue.
-
Method: insert (same as insert_after)
Summary: Insert a specified item into this queue, with the item having the
lower simulated time tag on top
Description:
Return: None
- item
- IN: specified item to insert into this queue.
-
Method: insert_after (same as insert)
Summary: Insert an item into this queue, with the item having the lower
simulated time tag on top
Description:
Return: None
- item
- IN: specified item to insert into this queue.
-
Method: join
Summary: Concatenate a specified queue to this queue, but do not reset
the specified (passed in) queue
Description:
Return: None
- q
- IN: specified queue to concatenate with this queue.
-
Method: length (same as get_length)
Summary: Get the number of items in the queue
Description: This method is perfect for finding out how many items
are in a queue before you start iterating through those
items.
Return: The number of items in the queue
-
Method: merge
Summary: Merge a specified queue into this queue in simulated time order
Description:
Return: None
- q
- IN: specified queue to merge with this queue.
-
- Method: next.
Summary: Get a pointer to the item in the queue immediately following (ie below) a specified item without removing it from the queue.
Description: This is a great way to walk through a queue and examine all the items. Notice that this list is not NULL terminated so you need to first find out how many items are in the list as in the following code:
C_ITEM * tempItem = queue->get_top(); int numItems = queue->get_length(); for (int i=0; i < numItems; ++i){ //Process tempItem here tempItem = queue->next(tempItem); }.
Return: A pointer to the item in the queue immediately following (ie below) a specified item without removing it from the queue.
- item
- IN: specified item after which the requested item lies.
-
Method: pbot (same as get_bot)
Summary: Get a pointer to the item at the bottom of the queue without
removing it from the queue.
Description:
Return: A pointer to the item at the bottom of the queue
-
Method: pop_top
Summary: Pops a specified item off of (ie, removes a specified item
from) the top of the queue and returns it
Description:
Return: Item that has been popped off of (removed from) the top of the queue
-
Method: print
Summary: Print the items in this queue
Description: This calls the virtual method print() on each of the
items in the queue.
Return: None
-
Method: printstream
Summary: print the items in this queue using stream io
Description: This calls the virtual method printstream() on each of
the items in the queue.
Return: None
- out
- IN: the ostream to which to print.
-
Method: ptop (same as get_top)
Summary: Get a pointer to the item at the top of the queue without removing
it from the queue.
Description:
Return: A pointer to the item at the top of the queue
-
Method: push_bot
Summary: Pushes a specified item onto (ie, inserts a specified item
at) the bottom of the queue
Description:
Return: None
- item
- IN: specified item to insert.
-
Method: push_top
Summary: Pushes a specified item onto (ie, inserts a specified item at) the
top of the queue
Description: This method moves the top pointer in this queue to the
specified item, which then points to the old top item
Return: None
-
Overloaded Method: remove
Summary: Remove (delete) an item from the queue
Description:
Return: None
- item
- IN: item to remove.
-
Overloaded Method: remove
Summary: Remove (delete) an item from the queue
Description: This removes the item from the queue and it also
deletes the item. Be sure not to try to access it if
you have a stale pointer to it!
Return: None
- id
- IN: ID of item to remove.
-
Method: reset
Summary: Clear this queue without deleting the items
Description: Sets top and bottom of this queue to NULL, and number of items
to zero
Return: None
-
Method: set_bot
Summary: Set the bottom of the queue to point to a specified item
Description: This should be called initially or just after clearing
the queue. Otherwise, calling this method will
permanently lose the current information in the queue
and create memory leaks.
Return: None
- item
- In: Item to be set as the top of the queue.
-
Method: set_length
Summary: Set the number of items in the queue (GET RID OF!)
Description: It is dangerous to try and use this method. Don't use
it unless you really know what you are doing. It can
result in the loss of data and the loss of pointers to
dynamically allocated memory.
Return: None
-
- IN: number of items in the queue.
- item
- In: Item to be set as the top of the queue.
-
- Method: sort Summary: Sort the queue in time order Description: If the number of items is 15 or less, this method uses insertion sort. Otherwise, it recursively divides the items into pairs of two halves until the number of items in each resulting half is 15 or less. These are sorted with insertion sort. Once each each pair has two sorted halves, the two halves are merged into one sorted temporary queue. Finally, it recursively merges all sorted temporary queues into the final sorted queue. Ie. It uses merge sort. Return: None.