A class that works just like a queue or a stack, except that a randomly selected element is returned. More...
Public Member Functions | |
def | __init__ |
Constructs a new empty RandomQueue. | |
def | empty |
Returns True if this RandomQueue is empty. | |
def | push |
Push a new element into the RandomQueue. | |
def | pop |
Pops a randomly selected element from the queue. | |
Public Attributes | |
array | |
The internal list to store objects. |
A class that works just like a queue or a stack, except that a randomly selected element is returned.
This class is useful for implementing algorithms that gather elements, and need to process them randomly. Something along the lines of:
while not rqueue.empty(): #generates 3 new elements to process for i in range(3): rqueue.push(process(rqueue.pop()))
Definition at line 51 of file enhanced_grid.py.
def enhanced_grid.RandomQueue.__init__ | ( | self | ) |
Constructs a new empty RandomQueue.
Definition at line 53 of file enhanced_grid.py.
def enhanced_grid.RandomQueue.empty | ( | self | ) |
Returns True if this RandomQueue is empty.
Definition at line 58 of file enhanced_grid.py.
def enhanced_grid.RandomQueue.pop | ( | self | ) |
Pops a randomly selected element from the queue.
All elements can be selected equiprobably
Definition at line 68 of file enhanced_grid.py.
def enhanced_grid.RandomQueue.push | ( | self, | ||
x | ||||
) |
Push a new element into the RandomQueue.
Definition at line 62 of file enhanced_grid.py.
The internal list to store objects.
Definition at line 55 of file enhanced_grid.py.