-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# 스택은 기본 리스트에서 append()와 pop()을 사용하기만 하면 쓸 수 있다 | ||
|
||
stack = [] | ||
|
||
stack.append(5) | ||
stack.append(2) | ||
stack.append(3) | ||
stack.append(7) | ||
stack.pop() | ||
stack.append(1) | ||
stack.append(4) | ||
stack.pop() | ||
|
||
print(stack) # 최하단 원소부터 | ||
print(stack[::-1]) # 최상단 원소부터 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Queue 라이브러리를 사용하기 위해서는 collections 모듈에서 제공하는 dqeue 자료구조를 활용해야 한다 (queue보다 효율적임) | ||
|
||
from collections import deque | ||
|
||
queue = deque() | ||
|
||
queue.append(5) | ||
queue.append(2) | ||
queue.append(3) | ||
queue.append(7) | ||
queue.popleft() | ||
queue.append(1) | ||
queue.append(4) | ||
queue.popleft() | ||
|
||
print(queue) | ||
queue.reverse() | ||
print(queue) | ||
print(list(queue)) # deque -> list 로 바꾸려면 list()로 감싸주기 |