IT 기술/Application

[java] Stack, Queue, ArrayDeque

->^_^<- 2021. 9. 4. 18:51
반응형

# Stack

- Last in First Out

- 스택은 ArrayList로 구현

Stack<Integer> st = new Stack<>();
st.push('10');
st.push('20');
st.push('30');

while(!st.empty()){
	System.out.println(st.pop());
}

 

 

# Queue

- First in First Out

- 큐는 LinkedList로 구현

Queue<Integer> q = new LinkedList<>();
q.offer('10');
q.offer('20');
q.offer('30');

while(!q.isEmpty()){
	System.out.println(q.poll());
}

- 큐를 ArrayDeque로 구현

Queue<Integer> q = new ArrayDeque<>();
q.add('10');
q.add('20');
q.add('30');

While(!q.isEmpty()){
	System.out.println(q.poll());
}

출처 : https://staticclass.tistory.com/100

 

# Deque(Double-Ended Queue)

출처 : https://staticclass.tistory.com/100

 

반응형