Skip to content

CircularQueue (Array-based)

Download Source Files NEW

Specification

IQueue

Bases: Generic[T]

Interface for a queue data structure

Source code in src/datastructures/iqueue.py
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 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
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
class IQueue(Generic[T]):
    ''' Interface for a queue data structure '''

    @abstractmethod
    def enqueue(self, item: T) -> None:
        ''' Enqueues an item into the queue.

            Arguments:
                item: T -- The item to enqueue.
        '''
        ...

    @abstractmethod
    def dequeue(self) -> T:
        ''' Dequeues an item from the queue.

            Returns:
                T -- The item dequeued from the queue.
        '''
        ...

    @abstractmethod
    def front(self) -> T:
        ''' Returns the front item in the queue without removing it.

            Returns:
                T -- The front item in the queue.
        '''
        ...

    @abstractmethod
    def back(self) -> T:
        ''' Returns the back item in the queue without removing it.

            Returns:
                T -- The back item in the queue.
        '''
        ...

    @abstractmethod
    def __len__(self) -> int:
        ''' Returns the number of items in the queue.   

            Returns:
                int -- The number of items in the queue.
        '''
        ...

    @abstractmethod
    def empty(self) -> bool:
        ''' Returns True if the queue is empty, False otherwise. 

            Returns:
                bool: True if the queue is empty, False otherwise.
        '''
        ...

    @abstractmethod
    def clear(self) -> None:
        ''' Clears the queue. '''
        ...

    @abstractmethod
    def __contains__(self, item: T) -> bool:
        ''' Returns True if the item is in the queue, False otherwise.

            Arguments:
                item: T -- The item to search for.

            Returns:
                bool: True if the item is in the queue, False otherwise.
        '''
        ...

    @abstractmethod
    def __eq__(self, other: object) -> bool:
        ''' Compares two queues for equality.

            Arguments:
                other: object -- The other queue to compare.

            Returns:
                bool -- True if the queues are equal, False otherwise.
        '''
        ...

    @abstractmethod
    def __str__(self) -> str:
        ''' Returns a string representation of the queue.

            Returns:
                str -- A string representation of the queue.
        '''
        ...

    @abstractmethod
    def __repr__(self) -> str:
        ''' Returns a string representation of the queue.

            Returns:
                str -- A string representation of the queue.
        '''
        ...

__contains__(item) abstractmethod

Returns True if the item is in the queue, False otherwise.

Parameters:

Name Type Description Default
item T

T -- The item to search for.

required

Returns:

Name Type Description
bool bool

True if the item is in the queue, False otherwise.

Source code in src/datastructures/iqueue.py
68
69
70
71
72
73
74
75
76
77
78
@abstractmethod
def __contains__(self, item: T) -> bool:
    ''' Returns True if the item is in the queue, False otherwise.

        Arguments:
            item: T -- The item to search for.

        Returns:
            bool: True if the item is in the queue, False otherwise.
    '''
    ...

__eq__(other) abstractmethod

Compares two queues for equality.

Parameters:

Name Type Description Default
other object

object -- The other queue to compare.

required

Returns:

Type Description
bool

bool -- True if the queues are equal, False otherwise.

Source code in src/datastructures/iqueue.py
80
81
82
83
84
85
86
87
88
89
90
@abstractmethod
def __eq__(self, other: object) -> bool:
    ''' Compares two queues for equality.

        Arguments:
            other: object -- The other queue to compare.

        Returns:
            bool -- True if the queues are equal, False otherwise.
    '''
    ...

__len__() abstractmethod

Returns the number of items in the queue.

Returns:

Type Description
int

int -- The number of items in the queue.

Source code in src/datastructures/iqueue.py
45
46
47
48
49
50
51
52
@abstractmethod
def __len__(self) -> int:
    ''' Returns the number of items in the queue.   

        Returns:
            int -- The number of items in the queue.
    '''
    ...

__repr__() abstractmethod

Returns a string representation of the queue.

Returns:

Type Description
str

str -- A string representation of the queue.

Source code in src/datastructures/iqueue.py
101
102
103
104
105
106
107
108
@abstractmethod
def __repr__(self) -> str:
    ''' Returns a string representation of the queue.

        Returns:
            str -- A string representation of the queue.
    '''
    ...

__str__() abstractmethod

Returns a string representation of the queue.

Returns:

Type Description
str

str -- A string representation of the queue.

Source code in src/datastructures/iqueue.py
92
93
94
95
96
97
98
99
@abstractmethod
def __str__(self) -> str:
    ''' Returns a string representation of the queue.

        Returns:
            str -- A string representation of the queue.
    '''
    ...

back() abstractmethod

Returns the back item in the queue without removing it.

Returns:

Type Description
T

T -- The back item in the queue.

Source code in src/datastructures/iqueue.py
36
37
38
39
40
41
42
43
@abstractmethod
def back(self) -> T:
    ''' Returns the back item in the queue without removing it.

        Returns:
            T -- The back item in the queue.
    '''
    ...

clear() abstractmethod

Clears the queue.

Source code in src/datastructures/iqueue.py
63
64
65
66
@abstractmethod
def clear(self) -> None:
    ''' Clears the queue. '''
    ...

dequeue() abstractmethod

Dequeues an item from the queue.

Returns:

Type Description
T

T -- The item dequeued from the queue.

Source code in src/datastructures/iqueue.py
18
19
20
21
22
23
24
25
@abstractmethod
def dequeue(self) -> T:
    ''' Dequeues an item from the queue.

        Returns:
            T -- The item dequeued from the queue.
    '''
    ...

empty() abstractmethod

Returns True if the queue is empty, False otherwise.

Returns:

Name Type Description
bool bool

True if the queue is empty, False otherwise.

Source code in src/datastructures/iqueue.py
54
55
56
57
58
59
60
61
@abstractmethod
def empty(self) -> bool:
    ''' Returns True if the queue is empty, False otherwise. 

        Returns:
            bool: True if the queue is empty, False otherwise.
    '''
    ...

enqueue(item) abstractmethod

Enqueues an item into the queue.

Parameters:

Name Type Description Default
item T

T -- The item to enqueue.

required
Source code in src/datastructures/iqueue.py
 9
10
11
12
13
14
15
16
@abstractmethod
def enqueue(self, item: T) -> None:
    ''' Enqueues an item into the queue.

        Arguments:
            item: T -- The item to enqueue.
    '''
    ...

front() abstractmethod

Returns the front item in the queue without removing it.

Returns:

Type Description
T

T -- The front item in the queue.

Source code in src/datastructures/iqueue.py
27
28
29
30
31
32
33
34
@abstractmethod
def front(self) -> T:
    ''' Returns the front item in the queue without removing it.

        Returns:
            T -- The front item in the queue.
    '''
    ...

CircularQueue

Bases: IQueue[T]

Represents a fixed-size circular queue. The queue is circular in the sense that the front and rear pointers wrap around the array when they reach the end. The queue is full when the rear pointer is one position behind the front pointer. The queue is empty when the front and rear pointers are equal. This implementation uses a fixed-size array.

Source code in src/datastructures/circularqueue.py
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 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
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
class CircularQueue(IQueue[T]):
    """ Represents a fixed-size circular queue. The queue
        is circular in the sense that the front and rear pointers wrap around the
        array when they reach the end. The queue is full when the rear pointer is
        one position behind the front pointer. The queue is empty when the front
        and rear pointers are equal. This implementation uses a fixed-size array.
    """

    def __init__(self, maxsize: int = 0, data_type=object) -> None:
        ''' Initializes the CircularQueue object with a maxsize and data_type.

            Examples:
                >>> q = CircularQueue(maxsize=5, data_type=int)
                >>> q.maxsize
                5
                >>> q.empty
                True
                >>> q.full
                False
                >>> q.front
                IndexError('Queue is empty')
                >>> q.rear
                IndexError('Queue is empty')

            Arguments:
                maxsize: The maximum size of the queue
                data_type: The type of the elements in the queue
        '''
        raise NotImplementedError

    def enqueue(self, item: T) -> None:
        ''' Adds an item to the rear of the queue

            Examples:
                >>> q = CircularQueue(maxsize=5, data_type=int)
                >>> q.enqueue(1)
                >>> q.enqueue(2)
                >>> q.enqueue(3)
                >>> q.front
                1
                >>> q.rear
                3
                >>> q.enqueue(4)
                >>> q.enqueue(5)
                >>> q.full
                True
                >>> q.enqueue(6)
                IndexError('Queue is full')

            Arguments:
                item: The item to add to the queue

            Raises:
                IndexError: If the queue is full
        '''
        raise NotImplementedError

    def dequeue(self) -> T:
        ''' Removes and returns the item at the front of the queue

            Examples:
                >>> q = CircularQueue(maxsize=5, data_type=int)
                >>> q.enqueue(1)
                >>> q.enqueue(2)
                >>> q.enqueue(3)
                >>> q.dequeue()
                1
                >>> q.dequeue()
                2
                >>> q.dequeue()
                3
                >>> q.dequeue()
                IndexError('Queue is empty')
                >>> q.dequeue()
                IndexError('Queue is empty')

            Returns:
                The item at the front of the queue

            Raises:
                IndexError: If the queue is empty
        '''
        raise NotImplementedError

    def clear(self) -> None:
        ''' Removes all items from the queue 

            Examples:
                >>> q = CircularQueue(maxsize=5, data_type=int)
                >>> q.enqueue(1)
                >>> q.enqueue(2)
                >>> q.enqueue(3)
                >>> q.clear()
                >>> q.empty
                True
                >>> q.front
                IndexError('Queue is empty')
                >>> q.rear
                IndexError('Queue is empty')
        '''
        raise NotImplementedError

    @property
    def front(self) -> T:
        ''' Returns the item at the front of the queue without removing it

            Examples:
                >>> q = CircularQueue(maxsize=5, data_type=int)
                >>> q.enqueue(1)
                >>> q.enqueue(2)
                >>> q.enqueue(3)
                >>> q.front
                1
                >>> q.dequeue()
                1
                >>> q.front
                2
                >>> q.dequeue()
                2
                >>> q.front
                3
                >>> q.dequeue()
                3
                >>> q.front
                IndexError('Queue is empty')

            Returns:
                The item at the front of the queue

            Raises:
                IndexError: If the queue is empty
        '''
        raise NotImplementedError

    @property
    def full(self) -> bool:
        ''' Returns True if the queue is full, False otherwise 

            Examples:
                >>> q = CircularQueue(maxsize=5, data_type=int)
                >>> q.full
                False
                >>> q.enqueue(1)
                >>> q.full
                False
                >>> q.enqueue(2)
                >>> q.full
                False
                >>> q.enqueue(3)
                >>> q.full
                False
                >>> q.enqueue(4)
                >>> q.full
                False
                >>> q.enqueue(5)
                >>> q.full
                True
                >>> q.dequeue()
                1
                >>> q.full
                False
                >>> q.dequeue()
                2
                >>> q.full
                False
                >>> q.dequeue()
                3
                >>> q.full
                False
                >>> q.dequeue()
                4
                >>> q.full
                False
                >>> q.dequeue()
                5
                >>> q.full
                False

            Returns:
                True if the queue is full, False otherwise
        '''
        raise NotImplementedError

    @property
    def empty(self) -> bool:
        ''' Returns True if the queue is empty, False otherwise

            Examples:
                >>> q = CircularQueue(maxsize=5, data_type=int)
                >>> q.empty
                True
                >>> q.enqueue(1)
                >>> q.empty
                False
                >>> q.enqueue(2)
                >>> q.empty
                False
                >>> q.enqueue(3)
                >>> q.empty
                False
                >>> q.enqueue(4)
                >>> q.empty
                False
                >>> q.enqueue(5)
                >>> q.empty
                False
                >>> q.dequeue()
                1
                >>> q.empty
                False
                >>> q.dequeue()
                2
                >>> q.empty
                False
                >>> q.dequeue()
                3
                >>> q.empty
                False
                >>> q.dequeue()
                4
                >>> q.empty
                False
                >>> q.dequeue()
                5
                >>> q.empty

            Returns:
                True if the queue is empty, False otherwise
        '''
        raise NotImplementedError

    @property
    def maxsize(self) -> int:
        ''' Returns the maximum size of the queue

            Examples:
                >>> q = CircularQueue(maxsize=5, data_type=int)
                >>> q.maxsize
                5

            Returns:
                The maximum size of the queue
        '''
        raise NotImplementedError

    def __eq__(self, other: object) -> bool:
        ''' Returns True if this CircularQueue is equal to another object, False otherwise

            Equality is defined as:
                - The element values at the front and rear pointers are equal
                - The element values between the front and rear pointers are equal
                - The maxsize of the queue is equal
                - The data_type of the queue is equal
                - Two queues are equal if they have the same elements in the same order, regardless of the index
                  of the front and rear pointers.

            Examples:
                >>> q1 = CircularQueue(maxsize=5, data_type=int)
                >>> q2 = CircularQueue(maxsize=5, data_type=int)
                >>> q1 == q2
                True
                >>> for i in range(5): q1.enqueue(i)
                >>> for i in range(5): q2.enqueue(i)
                >>> q1 == q2
                True
                >>> q1.dequeue()
                0
                >>> q1 == q2
                False

            Arguments:
                other: The object to compare this CircularQueue to

            Returns:
                True if this CircularQueue is equal to another object, False otherwise
        '''
        raise NotImplementedError   

    def __len__(self) -> int:
        ''' Returns the number of items in the queue

            Examples:
                >>> q = CircularQueue(maxsize=5, data_type=int)
                >>> len(q)
                0
                >>> q.enqueue(1)
                >>> len(q)
                1
                >>> q.enqueue(2)
                >>> len(q)
                2
                >>> q.enqueue(3)
                >>> len(q)
                3
                >>> q.dequeue()
                1
                >>> len(q)
                2
                >>> q.dequeue()
                2
                >>> len(q)
                1
                >>> q.dequeue()
                3
                >>> len(q)
                0

            Returns:
                The number of items in the queue
        '''
        raise NotImplementedError

    def __str__(self) -> str:
        ''' Returns a string representation of the CircularQueue

            Examples:
                >>> q = CircularQueue(maxsize=5, data_type=int)
                >>> q.enqueue(1)
                >>> q.enqueue(2)
                >>> q.enqueue(3)
                >>> print(q)
                [1, 2, 3]

            Returns:
                A string representation of the queue
        '''
        return str(self.circularqueue)

    def __repr__(self) -> str:
        ''' Returns a developer string representation of the CircularQueue object

            Examples:
                >>> q = CircularQueue(maxsize=5, data_type=int)
                >>> q.enqueue(1)
                >>> q.enqueue(2)
                >>> q.enqueue(3)
                >>> repr(q)
                'ArrayQueue([1, 2, 3])'

            Returns:
                A string representation of the CircularQueue object
        '''
        return f'ArrayQueue({repr(self.circularqueue)})'

empty property

Returns True if the queue is empty, False otherwise

Examples:

>>> q = CircularQueue(maxsize=5, data_type=int)
>>> q.empty
True
>>> q.enqueue(1)
>>> q.empty
False
>>> q.enqueue(2)
>>> q.empty
False
>>> q.enqueue(3)
>>> q.empty
False
>>> q.enqueue(4)
>>> q.empty
False
>>> q.enqueue(5)
>>> q.empty
False
>>> q.dequeue()
1
>>> q.empty
False
>>> q.dequeue()
2
>>> q.empty
False
>>> q.dequeue()
3
>>> q.empty
False
>>> q.dequeue()
4
>>> q.empty
False
>>> q.dequeue()
5
>>> q.empty

Returns:

Type Description
bool

True if the queue is empty, False otherwise

front property

Returns the item at the front of the queue without removing it

Examples:

>>> q = CircularQueue(maxsize=5, data_type=int)
>>> q.enqueue(1)
>>> q.enqueue(2)
>>> q.enqueue(3)
>>> q.front
1
>>> q.dequeue()
1
>>> q.front
2
>>> q.dequeue()
2
>>> q.front
3
>>> q.dequeue()
3
>>> q.front
IndexError('Queue is empty')

Returns:

Type Description
T

The item at the front of the queue

Raises:

Type Description
IndexError

If the queue is empty

full property

Returns True if the queue is full, False otherwise

Examples:

>>> q = CircularQueue(maxsize=5, data_type=int)
>>> q.full
False
>>> q.enqueue(1)
>>> q.full
False
>>> q.enqueue(2)
>>> q.full
False
>>> q.enqueue(3)
>>> q.full
False
>>> q.enqueue(4)
>>> q.full
False
>>> q.enqueue(5)
>>> q.full
True
>>> q.dequeue()
1
>>> q.full
False
>>> q.dequeue()
2
>>> q.full
False
>>> q.dequeue()
3
>>> q.full
False
>>> q.dequeue()
4
>>> q.full
False
>>> q.dequeue()
5
>>> q.full
False

Returns:

Type Description
bool

True if the queue is full, False otherwise

maxsize property

Returns the maximum size of the queue

Examples:

>>> q = CircularQueue(maxsize=5, data_type=int)
>>> q.maxsize
5

Returns:

Type Description
int

The maximum size of the queue

__eq__(other)

Returns True if this CircularQueue is equal to another object, False otherwise

Equality is defined as
  • The element values at the front and rear pointers are equal
  • The element values between the front and rear pointers are equal
  • The maxsize of the queue is equal
  • The data_type of the queue is equal
  • Two queues are equal if they have the same elements in the same order, regardless of the index of the front and rear pointers.

Examples:

>>> q1 = CircularQueue(maxsize=5, data_type=int)
>>> q2 = CircularQueue(maxsize=5, data_type=int)
>>> q1 == q2
True
>>> for i in range(5): q1.enqueue(i)
>>> for i in range(5): q2.enqueue(i)
>>> q1 == q2
True
>>> q1.dequeue()
0
>>> q1 == q2
False

Parameters:

Name Type Description Default
other object

The object to compare this CircularQueue to

required

Returns:

Type Description
bool

True if this CircularQueue is equal to another object, False otherwise

Source code in src/datastructures/circularqueue.py
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
def __eq__(self, other: object) -> bool:
    ''' Returns True if this CircularQueue is equal to another object, False otherwise

        Equality is defined as:
            - The element values at the front and rear pointers are equal
            - The element values between the front and rear pointers are equal
            - The maxsize of the queue is equal
            - The data_type of the queue is equal
            - Two queues are equal if they have the same elements in the same order, regardless of the index
              of the front and rear pointers.

        Examples:
            >>> q1 = CircularQueue(maxsize=5, data_type=int)
            >>> q2 = CircularQueue(maxsize=5, data_type=int)
            >>> q1 == q2
            True
            >>> for i in range(5): q1.enqueue(i)
            >>> for i in range(5): q2.enqueue(i)
            >>> q1 == q2
            True
            >>> q1.dequeue()
            0
            >>> q1 == q2
            False

        Arguments:
            other: The object to compare this CircularQueue to

        Returns:
            True if this CircularQueue is equal to another object, False otherwise
    '''
    raise NotImplementedError   

__init__(maxsize=0, data_type=object)

Initializes the CircularQueue object with a maxsize and data_type.

Examples:

>>> q = CircularQueue(maxsize=5, data_type=int)
>>> q.maxsize
5
>>> q.empty
True
>>> q.full
False
>>> q.front
IndexError('Queue is empty')
>>> q.rear
IndexError('Queue is empty')

Parameters:

Name Type Description Default
maxsize int

The maximum size of the queue

0
data_type

The type of the elements in the queue

object
Source code in src/datastructures/circularqueue.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def __init__(self, maxsize: int = 0, data_type=object) -> None:
    ''' Initializes the CircularQueue object with a maxsize and data_type.

        Examples:
            >>> q = CircularQueue(maxsize=5, data_type=int)
            >>> q.maxsize
            5
            >>> q.empty
            True
            >>> q.full
            False
            >>> q.front
            IndexError('Queue is empty')
            >>> q.rear
            IndexError('Queue is empty')

        Arguments:
            maxsize: The maximum size of the queue
            data_type: The type of the elements in the queue
    '''
    raise NotImplementedError

__len__()

Returns the number of items in the queue

Examples:

>>> q = CircularQueue(maxsize=5, data_type=int)
>>> len(q)
0
>>> q.enqueue(1)
>>> len(q)
1
>>> q.enqueue(2)
>>> len(q)
2
>>> q.enqueue(3)
>>> len(q)
3
>>> q.dequeue()
1
>>> len(q)
2
>>> q.dequeue()
2
>>> len(q)
1
>>> q.dequeue()
3
>>> len(q)
0

Returns:

Type Description
int

The number of items in the queue

Source code in src/datastructures/circularqueue.py
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
def __len__(self) -> int:
    ''' Returns the number of items in the queue

        Examples:
            >>> q = CircularQueue(maxsize=5, data_type=int)
            >>> len(q)
            0
            >>> q.enqueue(1)
            >>> len(q)
            1
            >>> q.enqueue(2)
            >>> len(q)
            2
            >>> q.enqueue(3)
            >>> len(q)
            3
            >>> q.dequeue()
            1
            >>> len(q)
            2
            >>> q.dequeue()
            2
            >>> len(q)
            1
            >>> q.dequeue()
            3
            >>> len(q)
            0

        Returns:
            The number of items in the queue
    '''
    raise NotImplementedError

__repr__()

Returns a developer string representation of the CircularQueue object

Examples:

>>> q = CircularQueue(maxsize=5, data_type=int)
>>> q.enqueue(1)
>>> q.enqueue(2)
>>> q.enqueue(3)
>>> repr(q)
'ArrayQueue([1, 2, 3])'

Returns:

Type Description
str

A string representation of the CircularQueue object

Source code in src/datastructures/circularqueue.py
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
def __repr__(self) -> str:
    ''' Returns a developer string representation of the CircularQueue object

        Examples:
            >>> q = CircularQueue(maxsize=5, data_type=int)
            >>> q.enqueue(1)
            >>> q.enqueue(2)
            >>> q.enqueue(3)
            >>> repr(q)
            'ArrayQueue([1, 2, 3])'

        Returns:
            A string representation of the CircularQueue object
    '''
    return f'ArrayQueue({repr(self.circularqueue)})'

__str__()

Returns a string representation of the CircularQueue

Examples:

>>> q = CircularQueue(maxsize=5, data_type=int)
>>> q.enqueue(1)
>>> q.enqueue(2)
>>> q.enqueue(3)
>>> print(q)
[1, 2, 3]

Returns:

Type Description
str

A string representation of the queue

Source code in src/datastructures/circularqueue.py
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
def __str__(self) -> str:
    ''' Returns a string representation of the CircularQueue

        Examples:
            >>> q = CircularQueue(maxsize=5, data_type=int)
            >>> q.enqueue(1)
            >>> q.enqueue(2)
            >>> q.enqueue(3)
            >>> print(q)
            [1, 2, 3]

        Returns:
            A string representation of the queue
    '''
    return str(self.circularqueue)

clear()

Removes all items from the queue

Examples:

>>> q = CircularQueue(maxsize=5, data_type=int)
>>> q.enqueue(1)
>>> q.enqueue(2)
>>> q.enqueue(3)
>>> q.clear()
>>> q.empty
True
>>> q.front
IndexError('Queue is empty')
>>> q.rear
IndexError('Queue is empty')
Source code in src/datastructures/circularqueue.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
def clear(self) -> None:
    ''' Removes all items from the queue 

        Examples:
            >>> q = CircularQueue(maxsize=5, data_type=int)
            >>> q.enqueue(1)
            >>> q.enqueue(2)
            >>> q.enqueue(3)
            >>> q.clear()
            >>> q.empty
            True
            >>> q.front
            IndexError('Queue is empty')
            >>> q.rear
            IndexError('Queue is empty')
    '''
    raise NotImplementedError

dequeue()

Removes and returns the item at the front of the queue

Examples:

>>> q = CircularQueue(maxsize=5, data_type=int)
>>> q.enqueue(1)
>>> q.enqueue(2)
>>> q.enqueue(3)
>>> q.dequeue()
1
>>> q.dequeue()
2
>>> q.dequeue()
3
>>> q.dequeue()
IndexError('Queue is empty')
>>> q.dequeue()
IndexError('Queue is empty')

Returns:

Type Description
T

The item at the front of the queue

Raises:

Type Description
IndexError

If the queue is empty

Source code in src/datastructures/circularqueue.py
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
def dequeue(self) -> T:
    ''' Removes and returns the item at the front of the queue

        Examples:
            >>> q = CircularQueue(maxsize=5, data_type=int)
            >>> q.enqueue(1)
            >>> q.enqueue(2)
            >>> q.enqueue(3)
            >>> q.dequeue()
            1
            >>> q.dequeue()
            2
            >>> q.dequeue()
            3
            >>> q.dequeue()
            IndexError('Queue is empty')
            >>> q.dequeue()
            IndexError('Queue is empty')

        Returns:
            The item at the front of the queue

        Raises:
            IndexError: If the queue is empty
    '''
    raise NotImplementedError

enqueue(item)

Adds an item to the rear of the queue

Examples:

>>> q = CircularQueue(maxsize=5, data_type=int)
>>> q.enqueue(1)
>>> q.enqueue(2)
>>> q.enqueue(3)
>>> q.front
1
>>> q.rear
3
>>> q.enqueue(4)
>>> q.enqueue(5)
>>> q.full
True
>>> q.enqueue(6)
IndexError('Queue is full')

Parameters:

Name Type Description Default
item T

The item to add to the queue

required

Raises:

Type Description
IndexError

If the queue is full

Source code in src/datastructures/circularqueue.py
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
def enqueue(self, item: T) -> None:
    ''' Adds an item to the rear of the queue

        Examples:
            >>> q = CircularQueue(maxsize=5, data_type=int)
            >>> q.enqueue(1)
            >>> q.enqueue(2)
            >>> q.enqueue(3)
            >>> q.front
            1
            >>> q.rear
            3
            >>> q.enqueue(4)
            >>> q.enqueue(5)
            >>> q.full
            True
            >>> q.enqueue(6)
            IndexError('Queue is full')

        Arguments:
            item: The item to add to the queue

        Raises:
            IndexError: If the queue is full
    '''
    raise NotImplementedError