Queues¶
- class pydatastructs.Queue(implementation='array', **kwargs)¶
Representation of queue data structure.
- Parameters
implementation (str) – Implementation to be used for queue. By default, ‘array’
items (list/tuple) – Optional, by default, None The inital items in the queue.
dtype (A valid python type) – Optional, by default NoneType if item is None. Required only for ‘array’ implementation.
double_ended (bool) – Optional, by default, False. Set to True if the queue should support additional, appendleft and pop operations from left and right sides respectively.
Examples
>>> from pydatastructs import Queue >>> q = Queue() >>> q.append(1) >>> q.append(2) >>> q.append(3) >>> q.popleft() 1 >>> len(q) 2
References
- append(*args, **kwargs)¶
- appendleft(*args, **kwargs)¶
- pop(*args, **kwargs)¶
- popleft(*args, **kwargs)¶
- property is_empty¶
- __module__ = 'pydatastructs.miscellaneous_data_structures.queue'¶
- class pydatastructs.PriorityQueue(implementation='binary_heap', **kwargs)¶
Represents the concept of priority queue.
- Parameters
implementation (str) –
The implementation which is to be used for supporting operations of priority queue. The following implementations are supported, ‘linked_list’ -> Linked list implementation. ‘binary_heap’ -> Binary heap implementation. ‘binomial_heap’ -> Binomial heap implementation.
Doesn’t support custom comparators, minimum key data is extracted in every pop.
Optional, by default, ‘binary_heap’ implementation is used.
comp (function) – The comparator to be used while comparing priorities. Must return a bool object. By default, lambda u, v: u < v is used to compare priorities i.e., minimum priority elements are extracted by pop operation.
Examples
>>> from pydatastructs import PriorityQueue >>> pq = PriorityQueue() >>> pq.push(1, 2) >>> pq.push(2, 3) >>> pq.pop() 1 >>> pq2 = PriorityQueue(comp=lambda u, v: u > v) >>> pq2.push(1, 2) >>> pq2.push(2, 3) >>> pq2.pop() 2
References
- push(value, priority)¶
Pushes the value to the priority queue according to the given priority.
- value
Value to be pushed.
- priority
Priority to be given to the value.
- pop()¶
Pops out the value from the priority queue.
- property peek¶
Returns the pointer to the value which will be popped out by pop method.
- property is_empty¶
Checks if the priority queue is empty.
- __module__ = 'pydatastructs.miscellaneous_data_structures.queue'¶