New World
[Zero-base #02] 큐 본문
728x90
    
    
  반응형
    
    
    
  
큐
- 선입선출(FIFO) 자료구조 : 먼저 들어온 데이터가 먼저 나가는 구조
- 입력 순서대로 데이터 처리가 필요할 때 사용 ex. 프린터 출력 대기열, BFS 등
큐 기본 연산
- 데이터 추가 (Enqueue)
- 데이터 꺼내기 (Dequeue)
| 값 추가 | 값 확인 | 값 제거 | 
| 큐의 맨 뒤에 값 삽입 | 큐의 맨 앞에 있는 값 반환 | remove() 큐 맨 앞에 있는 값 반환 후 삭제 큐가 비어 있는 경우 NoSuchElementException 에러 | 
| add() 꽉 찬 경우 IllegalStateException 에러 | element() 빈 경우 NoSuchElementException 에러 | poll() 큐 맨 앞에 있는 값 반환 후 삭제 큐가 비어있을 경우 null 반환 | 
| offer() 꽉 찬 경우 false 반환 | peek() 빈 경우 false 반환 | clear() 큐 비우기 | 
기능개발(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();
    }
}반응형
    
    
    
  'Self-Study > Study' 카테고리의 다른 글
| [회고 #0]프론트엔드와 백엔드 차이 - 백엔드 개발자가 되고 싶은 이유 (0) | 2023.03.17 | 
|---|---|
| [Zero-base #03] 배열 (0) | 2023.03.15 | 
| [Zero-Base #01] 스택 (0) | 2023.03.14 | 
| [개념 정리 #12] 나중에 다시 정리할 것들 (0) | 2022.10.27 | 
| [개념정리 #10] Database (0) | 2022.10.26 | 
			  Comments
			
		
	
               
           
					
					
					
					
					
					
				 
								 
								