자료구조
-
PriorityQueue자료구조 2023. 6. 15. 16:27
개념 PriorityQueue는 인터페이스로 Queue를 implements 받으며, Queue처럼 FIFO(First In First Out)의 구조를 갖긴 하지만, 내부적으로 우선순위를 정하여 그 우선 순위가 높은 데이터를 먼저 내보내는 자료구조이다. 이러한 우선순위 큐는 Heap을 이용하여 구현하는데, 데이터 삽입 시, 최대값이 우선순위인 큐를 최대힙 , 최소값이 우선순위인 큐를 최소힙이라고 한다. 때문에 우선순위 큐에 들어가는 원소는 비교가 가능한 기준이 있어야한다는 특징이 있다. 우선 순위 큐의 선언 queue interface를 상속받고 있지만, 구현체인 PriorityQueue 내부적으로 더많은 기능을 제공하므로 PriorityQueue를 선언하는 것이 일반적이다. // 우선순위가 낮은 in..
-
LinkedHashSet자료구조 2023. 6. 15. 07:46
개념 Set 타입들이 가지고 있는 특징은, 중복을 허용하지 않는다. 값을 넣은 순서를 보장하지 않는다. LinkedHashSet의 경우, 중복을 허용하지 않으면서 값을 넣은 순서를 보장해주는 자료구조이다. import java.util.HashSet; import java.util.LinkedHashSet; public class LinkedHashSetMain { public static void main(String[] args) { LinkedHashSet linkedHashSet = new LinkedHashSet(); HashSet set = new HashSet(); linkedHashSet.add("가"); linkedHashSet.add("나"); linkedHashSet.add("다");..
-
Stack / Queue자료구조 2023. 6. 14. 02:28
Stack - FILO: (First In Last Out) 구조의 자료형 - 스택은 구현체가 존재하므로 new Stack(); 로 선언하여 사용하면 된다. Stack - CRUD Create : push() : stack의 자료구조의 맨위에 넣음 Read : peek() : 맨 위의 값을 가지고옴 Update : set(index, ) : 값을 변경 Delete : pop() : 맨 위의 값을 꺼내면서(return), 삭제 Queue - FIFO : (First In First Out) 형태의 자료 구조 - Queue는 인터페이스이므로, 구현체를 필요로 한다. 이 때, 주로 사용하는 Queue 인터페이스의 구현체는 LinkedList를 사용한다. Queue - CRUD Create : add() : Q..