반응형

이 게시물은 다음 링크를 참조하여 학습했습니다.

 

Stack (Java Platform SE 7 )

The Stack class represents a last-in-first-out (LIFO) stack of objects. It extends class Vector with five operations that allow a vector to be treated as a stack. The usual push and pop operations are provided, as well as a method to peek at the top item o

docs.oracle.com

 

1. stack?

stack은 LIFO(Last-In-First-Out)의 형태를 갖는 자료구조이다.

쉽게 생각하면 박스에 물건을 적재할 때, 가장 마지막에 넣은 물건부터 꺼낼 수 있는 그런 자료구조이다.

stack을 사용하려면 아래처럼 사용하면 된다.

1
Stack<Integer> stack = new Stack<>();
cs

 

 

1-1. 메서드

(1) boolean isEmpty()

Stack이 비어있는지 확인한다.

 

(2) E peek()

Stack의 최상단 값을 반환한다.

 

(3) E pop()

Stack의 최상단 값을 제거한다. 제거 후 반환

 

(4) E push(E item)

Stack에 item을 넣어준다.

 

(5) int search(Object o)

Stack에서 o를 찾고 index를 반환한다. 없으면 -1 반환

 

반응형

'Legacy' 카테고리의 다른 글

[Kotlin #1] 기본문법  (0) 2022.05.11
[Java#7] Queue, Deque, PriorityQueue  (0) 2022.05.04
[Java#5] Set, HashSet, TreeSet  (0) 2022.05.03
[Java#4] Map, HashMap, TreeMap  (0) 2022.05.03
[Java#3] Array, ArrayList, Arrays  (0) 2022.05.02

+ Recent posts