방명록
- stack,queue2021년 03월 30일 15시 39분 39초에 업로드 된 글입니다.작성자: 원2728x90반응형
import java.util.*; public class Ex11_2 { public static void main(String[] args) { Stack st = new Stack(); Queue q = new LinkedList(); // Queue 인터페이스의 구현체인 LinkedList를 사용 st.push("0"); st.push("1"); st.push("2"); q.offer("0"); q.offer("1"); q.offer("2"); System.out.println("= stack ="); while(!st.empty()) { // empty() Stack이 비어있는지 알려준다. System.out.println(st.pop()); // st.pop() 스택에서 요소 하나를 꺼내서 출력 } System.out.println("= queue ="); while(!q.isEmpty()) { // empty() Stack이 비어있는지 알려준다. System.out.println(q.poll()); // q.poll() 큐에서 요소 하나를 꺼내서 출력 } } }
728x90반응형'Language > Java' 카테고리의 다른 글
Arrays Method - 변환 // 수정필 (0) 2021.03.30 binarySearch (0) 2021.03.30 람다식 lambda (0) 2021.03.30 copyOf(), copyOfRange() - Arrays의 메서드 (0) 2021.03.30 for each 문 (0) 2021.03.30 iterator (0) 2021.03.30 다음글이 없습니다.이전글이 없습니다.댓글