| 동적 배열 |
list (내장) |
|
|
arr = [1, 2, 3]arr.append(4) |
**ArrayList**List<Integer> list = new ArrayList<>();list.add(1); |
Array (내장) |
|
const arr = [1, 2, 3];arr.push(4); |
|
|
|
| 연결 리스트 |
**collections.deque**from collections import dequedq = deque([1, 2, 3]) |
**LinkedList**LinkedList<Integer> list = new LinkedList<>();list.add(1); |
직접 구현 필요 또는 배열로 대체 |
| 스택 |
list 또는 **deque**stack = []stack.append(1) (push) |
|
|
stack.pop() |
Deque<Integer> (ArrayDeque 권장) |
|
|
Deque<Integer> stack = new ArrayDeque<>();stack.push(1);stack.pop(); |
**Array**const stack = [];stack.push(1);stack.pop(); |
|
|
| 큐 |
**collections.deque**from collections import dequeq = deque()q.append(1) (enqueue) |
|
|
q.popleft() (dequeue) |
|
|
|
Queue<Integer> (LinkedList 권장) |
|
|
|
Queue<Integer> q = new LinkedList<>();q.offer(1);q.poll(); |
**Array**const queue = [];queue.push(1);queue.shift(); |
|
|
| 덱(양방향 큐) |
**collections.deque**dq.append(1) (오른쪽) |
|
|
dq.appendleft(0) (왼쪽) |
|
|
|
dq.pop() (오른쪽 제거) |
|
|
|
dq.popleft() (왼쪽 제거) |
|
|
|
Deque<Integer> (ArrayDeque 권장) |
|
|
|
dq.addLast(1);dq.addFirst(0);dq.pollLast();dq.pollFirst(); |
**Array**arr.push(1); (끝) |
|
|
arr.unshift(0); (앞) |
|
|
|
arr.pop(); (끝 제거) |
|
|
|
arr.shift(); (앞 제거) |
|
|
|
| 해시맵 |
dict (내장) |
|
|
map = {'key': 'value'}map['key'] |
|
|
|
또는 collections.defaultdict |
**HashMap<K, V>**Map<String, Integer> map = new HashMap<>();map.put("key", 1);map.getOrDefault("key", 0); |
Map (ES6) |
|
const map = new Map();map.set('key', 'value');map.get('key'); |
|
|
|
또는 Object |
|
|
|
| 해시셋 |
set (내장) |
|
|
s = {1, 2, 3}s.add(4)1 in s (True) |
|
|
|
**HashSet<T>**Set<Integer> set = new HashSet<>();set.add(1);set.contains(1); |
Set (ES6) |
|
|
const set = new Set([1, 2, 3]);set.add(4);set.has(1); (true) |
|
|
|
|
|
|
|
| 우선순위 큐 (힙) |
heapq (최소힙) |
|
|
import heapqheap = []heapq.heappush(heap, 3)heapq.heappop(heap) |
**PriorityQueue<T>**PriorityQueue<Integer> pq = new PriorityQueue<>();pq.offer(3);pq.poll(); |
내장 없음 |
|
직접 구현 또는 heap-js 패키지 사용 |
|
|
|
| [📦 NPM] |
|
|
|
| 정렬된 맵 (TreeMap) |
내장 없음 |
|
|
sortedcontainers 패키지 (외부 설치) |
|
|
|
| [📦 PyPI] |
**TreeMap<K, V>**Map<String, Integer> tm = new TreeMap<>();tm.put("b", 2);tm.put("a", 1);(자동 정렬됨) |
내장 없음 |
|
| 직접 구현 필요 |
|
|
|
| 정렬된 셋 (TreeSet) |
내장 없음 |
|
|
sortedcontainers 패키지 (외부 설치) |
|
|
|
| [📦 PyPI] |
**TreeSet<T>**Set<Integer> ts = new TreeSet<>();ts.add(3);ts.add(1);(자동 정렬됨) |
내장 없음 |
|
| 직접 구현 필요 |
|
|
|