Skip to content

Commit

Permalink
[#7] 이것이 파이썬 코딩테스트다 BFS DFS 2문제
Browse files Browse the repository at this point in the history
  • Loading branch information
hyesuuou committed Feb 9, 2022
1 parent fe823b6 commit 4a1e4a4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
16 changes: 16 additions & 0 deletions PythonCodingTest/DFS-BFS/5-1.py
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]) # 최상단 원소부터

19 changes: 19 additions & 0 deletions PythonCodingTest/DFS-BFS/5-2.py
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()로 감싸주기

0 comments on commit 4a1e4a4

Please sign in to comment.