본문 바로가기

Queue7

[Week 1 - Day 2] Python 3,4,5 1. 강의 내용 3-1. Python Data Structure - 스택과 큐 스택 : 나중에 넣은 데이터를 먼저 반환하도록 설계된 메모리 구조 (LIFO) 리스트, collections.deque() 사용 큐 : 먼저 넣은 데이터를 먼저 반환하도록 설계된 메모리 구조 리스트 - append(),get(), pop(0) - 튜플과 집합 tuple : 값의 변경이 불가능한 리스트 연산,인덱싱, 슬라이싱 가능 프로그램을 작동하는 동안 변경되지 않는 데이터의 저장 (학번, 이름 등) (1) 하나만 넣으면 정수로 인식 집합(set) : 값을 순서없이 저장, 중복 없이 intersection()교집합, difference()차집합 - 사전 (dict): key값(데이터를 구분 지을 수 있는 고유한 값)-value.. 2021. 8. 3.
[스택/큐] 프린터 ( any ) # Problem 일반적인 프린터는 인쇄 요청이 들어온 순서대로 인쇄합니다. 그렇기 때문에 중요한 문서가 나중에 인쇄될 수 있습니다. 이런 문제를 보완하기 위해 중요도가 높은 문서를 먼저 인쇄하는 프린터를 개발했습니다. 이 새롭게 개발한 프린터는 아래와 같은 방식으로 인쇄 작업을 수행합니다. 1. 인쇄 대기목록의 가장 앞에 있는 문서(J)를 대기목록에서 꺼냅니다. 2. 나머지 인쇄 대기목록에서 J보다 중요도가 높은 문서가 한 개라도 존재하면 J를 대기목록의 가장 마지막에 넣습니다. 3. 그렇지 않으면 J를 인쇄합니다. 예를 들어, 4개의 문서(A, B, C, D)가 순서대로 인쇄 대기목록에 있고 중요도가 2 1 3 2 라면 C D A B 순으로 인쇄하게 됩니다. 내가 인쇄를 요청한 문서가 몇 번째로 인쇄.. 2021. 6. 9.
[Baekjoon] 1966. 프린터 큐 # Problem 여러분도 알다시피 여러분의 프린터 기기는 여러분이 인쇄하고자 하는 문서를 인쇄 명령을 받은 ‘순서대로’, 즉 먼저 요청된 것을 먼저 인쇄한다. 여러 개의 문서가 쌓인다면 Queue 자료구조에 쌓여서 FIFO - First In First Out - 에 따라 인쇄가 되게 된다. 하지만 상근이는 새로운 프린터기 내부 소프트웨어를 개발하였는데, 이 프린터기는 다음과 같은 조건에 따라 인쇄를 하게 된다. 현재 Queue의 가장 앞에 있는 문서의 ‘중요도’를 확인한다. 나머지 문서들 중 현재 문서보다 중요도가 높은 문서가 하나라도 있다면, 이 문서를 인쇄하지 않고 Queue의 가장 뒤에 재배치 한다. 그렇지 않다면 바로 인쇄를 한다. 예를 들어 Queue에 4개의 문서(A B C D)가 있고, .. 2021. 4. 15.
[LEET CODE] 622. Design Circular Queue # Problem Design your implementation of the circular queue. The circular queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle and the last position is connected back to the first position to make a circle. It is also called "Ring Buffer". One of the benefits of the circular queue is that we can make use of the spaces in front of the .. 2021. 3. 29.
[LEET CODE] 232. Implement Queue using Stacks # Problem Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty). Implement the MyQueue class: void push(int x) Pushes element x to the back of the queue. int pop() Removes the element from the front of the queue and returns it. int peek() Returns the element at the front of the queu.. 2021. 3. 26.
[LEET CODE] 225. Implement Stack using Queues # Problem Implement a last in first out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal queue (push, top, pop, and empty). Implement the MyStack class: void push(int x) Pushes element x to the top of the stack. int pop() Removes the element on the top of the stack and returns it. int top() Returns the element on the top of the stack. boolean.. 2021. 3. 26.
반응형