Skip to Content
똑똑한 코드 작성을 위한 실전 알고리즘
book

똑똑한 코드 작성을 위한 실전 알고리즘

by 조지 하이네만, 윤대석
May 2022
Beginner to intermediate
296 pages
5h 54m
Korean
Hanbit Media, Inc.
Content preview from 똑똑한 코드 작성을 위한 실전 알고리즘
288
똑똑한 코드 작성을 위한 실전 알고리즘
8.2
스택 구현하기
파이썬
list
는 새로운 값을 리스트의 마지막에 넣는
append
()
함수를 제공해 스택을 표현할
수 있다 ([표
6
-
1
]를 보면 알 수 있듯 리스트의 마지막에 값을 추가하면 효율적이다 ).
list
입은
list
의 마지막 값을 반환하고 제거하는
pop
()
메서드를 실제 가지고 있다.
파이썬은 ‘후입 선출 (
LIFO
)’ 동작 (일반 스택의 방식 )과 ‘선입 선출 (
FIFO
)’ 동작 (큐의 방식 )
을 모두 지원하는
다중 생산자
,
다중 소비자
스택을 구현하는
queue
모듈을 제공한다.
queue
.
LifeQueue
(
maxSize
=
0
)
생성자 호출은 값의 최대 개수를 저장하는 스택을 반환한다. 이
스택은 동시에 사용될 수 있으며, 이는 가득 찬 스택에 값 넣기를 시도하면 값이 꺼내어질 때까
지 실행을 중지한다는 의미다. 값은
put
(
value
)
로 넣고
get
()
으로 꺼낸다. 다음과 같은 일련
의 명령을 수행하면 파이썬 인터프리터가 멈추고, 당신은 강제로 인터프리터를 중지해야 할 것
이다.
>>> import queue
>>> q = queue.LifoQueue(3)
>>> q.put(9)
>>> q.put(7)
>>> q.put(4)
>>> q.put(3)
... 강제 종료 전까지 멈춤
앞서 본 바와 같이 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

데이터 익명화를 위한 파이프라인

데이터 익명화를 위한 파이프라인

루크 아버클, 칼리드 엘 에맘
개발 7년차, 매니저 1일차

개발 7년차, 매니저 1일차

권원상, 한민주, 카미유 푸르니에

Publisher Resources

ISBN: 9791162245644