(제로 베이스 #02) 큐


예어

– 선입선출(FIFO) 데이터 구조: 선입선출 데이터 구조

– 입력 순서대로 데이터 처리가 필요할 때 사용합니다. 프린터 출력 큐, BFS 등

대기열 기본 작업

– 데이터 추가(인큐)

– 데이터를 대기열에서 빼기

부가 가치 값 확인 가치를 제거하다
대기열 끝에 값 삽입 대기열의 시작 부분에 있는 값을 반환합니다. 제거됨()
대기열의 시작 부분에서 값을 반환하고 버립니다.
대기열이 비어 있을 때 NoSuchElementException 실수

에 추가()
가득 찼을 때 IllegalStateException 오류
요소()
빈 케이스 NoSuchElementException 실수
여론조사()
대기열의 시작 부분에서 값을 반환하고 버립니다.
큐가 비어 있으면 null을 반환합니다.
권하다()
가득 차면 false 반환
몰래 엿보다()
비어 있으면 거짓 반환
분명한()
대기열 비우기

기능 개발 (https://school.programmers.co.kr/learn/courses/30/lessons/42586)

import java.util.*;

class Solution {
    public int() solution(int() progresses, int() speeds) {
        Queue<Integer> pspeeds = new LinkedList<Integer>();
        
        //수행하는데 걸리는 스피드
        for(int i = 0; i < progresses.length; i++){
            pspeeds.add((int) Math.ceil((100.0 - progresses(i)) / speeds(i)));
        }
        
        
        //수행하는데 걸리는 날짜
        ArrayList<Integer> days = new ArrayList<Integer>();
        
        while(!pspeeds.isEmpty()){
            int n = pspeeds.poll();
            int day = 1;
            
            while(!pspeeds.isEmpty() && n >= pspeeds.peek()){
                day++;
                pspeeds.poll();
            }
            days.add(day);
        }
        
        return days.stream().mapToInt(Integer::intValue).toArray();
    }
}