mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Update and rename circular_queue_II.py to circular_queue_list.py
This commit is contained in:
parent
71ca605489
commit
afe695c69f
@ -2,6 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# author: bt3gl
|
||||
|
||||
|
||||
class CircularQueue:
|
||||
|
||||
def __init__(self, k: int):
|
||||
@ -14,7 +15,6 @@ class CircularQueue:
|
||||
return (end + 1) % self.size
|
||||
|
||||
def enqueue(self, value: int) -> bool:
|
||||
|
||||
if self.is_full():
|
||||
return False
|
||||
|
||||
@ -23,11 +23,9 @@ class CircularQueue:
|
||||
|
||||
self.tail = self._get_next_position(self.tail)
|
||||
self.queue[self.tail] = value
|
||||
|
||||
return True
|
||||
|
||||
def dequeue(self) -> bool:
|
||||
|
||||
if self.is_empty():
|
||||
return False
|
||||
|
||||
@ -37,15 +35,14 @@ class CircularQueue:
|
||||
return True
|
||||
|
||||
self.head = self._get_next_position(self.head)
|
||||
|
||||
return True
|
||||
|
||||
def Front(self) -> int:
|
||||
def front(self) -> int:
|
||||
if self.is_empty():
|
||||
return -1
|
||||
return self.queue[self.head]
|
||||
|
||||
def Rear(self) -> int:
|
||||
def rear(self) -> int:
|
||||
if self.is_empty():
|
||||
return -1
|
||||
return self.queue[self.tail]
|
Loading…
x
Reference in New Issue
Block a user