일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 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 |
Tags
- kaggle
- attribute
- Protocol
- Convert Sorted List to Binary Search Tree
- LeetCode
- t1
- 715. Range Module
- 109. Convert Sorted List to Binary Search Tree
- Decorator
- iterator
- concurrency
- data science
- Substring with Concatenation of All Words
- shiba
- Generator
- DWG
- Python Code
- 밴픽
- 프로그래머스
- 운영체제
- 파이썬
- Regular Expression
- 30. Substring with Concatenation of All Words
- 43. Multiply Strings
- 315. Count of Smaller Numbers After Self
- Python
- 컴퓨터의 구조
- Python Implementation
- Class
- 시바견
Archives
- Today
- Total
Scribbling
Implementing Circular Queue with Python 본문
class Queue:
def __init__(self, size):
self.size = size
self.q = [0] * size
self.cnt = 0
self.head, self.tail = 0, 0
def append(self, val):
if self.cnt == self.size:
print('Full Queue Error')
return False
self.cnt += 1
self.q[self.tail] = val
self.tail += 1
if self.tail == self.size:
self.tail = 0
return True
def popleft(self):
if self.cnt == 0:
print('Empty Queue Error')
return False
self.cnt -= 1
ret = self.q[self.head]
self.head += 1
if self.head == self.size:
self.head = 0
return ret
def __repr__(self):
ret = '['
if self.cnt > 0:
if self.head < self.tail:
for i in range(self.head, self.tail):
ret += str(self.q[i]) + ', '
else:
for i in range(self.head, self.size):
ret += str(self.q[i]) + ', '
for i in range(self.tail):
ret += str(self.q[i]) + ', '
ret = ret[:-2]
ret += ']'
return ret
'Computer Science > Python' 카테고리의 다른 글
Python: Class Metaprogramming (클래스 메타프로그래밍) (0) | 2022.06.17 |
---|---|
Python: Attribute Descriptors (속성 디스크립터) (0) | 2022.06.17 |
Python: Dynamic attributes and properties (동적 속성과 프로퍼티) (0) | 2022.06.17 |
Python: Concurrency with asyncio (asyncio 기반 비동기 프로그래밍) (0) | 2022.05.17 |
Zip & Unpacking (0) | 2022.05.10 |