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 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# author: bt3gl
|
# author: bt3gl
|
||||||
|
|
||||||
|
|
||||||
class CircularQueue:
|
class CircularQueue:
|
||||||
|
|
||||||
def __init__(self, k: int):
|
def __init__(self, k: int):
|
||||||
@ -14,7 +15,6 @@ class CircularQueue:
|
|||||||
return (end + 1) % self.size
|
return (end + 1) % self.size
|
||||||
|
|
||||||
def enqueue(self, value: int) -> bool:
|
def enqueue(self, value: int) -> bool:
|
||||||
|
|
||||||
if self.is_full():
|
if self.is_full():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -23,11 +23,9 @@ class CircularQueue:
|
|||||||
|
|
||||||
self.tail = self._get_next_position(self.tail)
|
self.tail = self._get_next_position(self.tail)
|
||||||
self.queue[self.tail] = value
|
self.queue[self.tail] = value
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def dequeue(self) -> bool:
|
def dequeue(self) -> bool:
|
||||||
|
|
||||||
if self.is_empty():
|
if self.is_empty():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -37,15 +35,14 @@ class CircularQueue:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
self.head = self._get_next_position(self.head)
|
self.head = self._get_next_position(self.head)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def Front(self) -> int:
|
def front(self) -> int:
|
||||||
if self.is_empty():
|
if self.is_empty():
|
||||||
return -1
|
return -1
|
||||||
return self.queue[self.head]
|
return self.queue[self.head]
|
||||||
|
|
||||||
def Rear(self) -> int:
|
def rear(self) -> int:
|
||||||
if self.is_empty():
|
if self.is_empty():
|
||||||
return -1
|
return -1
|
||||||
return self.queue[self.tail]
|
return self.queue[self.tail]
|
Loading…
x
Reference in New Issue
Block a user