Queue ADT
Abstract Class IQueue
¶
Bases: Sized
, Iterable
IQueue
provides an interface for the Queue ADT that supports the
Pythonic way of iterating over elements and querying collection size.
Implementations of this ADT must implement the abstract methods
__len__()
, __iter__()
, front()
, enqueue()
, and
dequeue()
. In addition, the abstract property element_type
also
has to be implemented, and it is suggested to acquire this data via
__init__()
with an argument of type pydsa.utils.ElemTypeName
.
Source code in pydsa/queue/adt.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
__str__()
¶
String representation of the queue, listing elements in queue order from left to right.
Example
[3,1,4,1,5]
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The string representation. |
Source code in pydsa/queue/adt.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
dequeue()
abstractmethod
¶
Removes the front element from the queue if it is not empty.
Returns:
Name | Type | Description |
---|---|---|
Elem |
Elem
|
description |
Source code in pydsa/queue/adt.py
82 83 84 85 86 87 88 |
|
element_type()
property
abstractmethod
¶
String representation of the type of each element in the queue.
Returns:
Name | Type | Description |
---|---|---|
Type |
ElemTypeName
|
The element type string. |
Source code in pydsa/queue/adt.py
57 58 59 60 61 62 63 64 |
|
empty()
property
¶
Checks if the queue is empty.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the queue contains no elements. |
Source code in pydsa/queue/adt.py
28 29 30 31 32 33 34 35 |
|
enqueue(elem)
abstractmethod
¶
Inserts an element at the end of the queue.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
elem |
Elem
|
The element to insert. |
required |
Source code in pydsa/queue/adt.py
74 75 76 77 78 79 80 |
|
front()
abstractmethod
¶
Gets the element at the front of the queue if it is not empty.
Returns:
Name | Type | Description |
---|---|---|
Elem |
Elem
|
The front element. |
Source code in pydsa/queue/adt.py
66 67 68 69 70 71 72 |
|