일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 30. Substring with Concatenation of All Words
- 파이썬
- 315. Count of Smaller Numbers After Self
- Convert Sorted List to Binary Search Tree
- Substring with Concatenation of All Words
- Regular Expression
- iterator
- Python Implementation
- 109. Convert Sorted List to Binary Search Tree
- 밴픽
- 43. Multiply Strings
- concurrency
- Decorator
- 프로그래머스
- Protocol
- 운영체제
- data science
- shiba
- DWG
- 시바견
- LeetCode
- Python Code
- 컴퓨터의 구조
- Class
- Generator
- t1
- kaggle
- Python
- attribute
- 715. Range Module
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 |