2.9 알고리즘2

jihyun·2023년 2월 10일

알고리즘

목록 보기
2/4

스택

한쪽 끝에서만 자료를 넣고(push) 뺄(pop) 수 있는 자료구조


const push = (item) => {
  stack[size] = item;
  size += 1
}

const pop = () => {
    size -= 1
	return stack[size]
}

스택은 맨 위에서만 push, pop할 수 있다.
=LIFO(Last In First Out)

한쪽 끝에서만 자료를 넣고(push) 다른 한쪽 끝에서만 뺄 (pop) 수 있는 자료구조
= FIFO(First In First Out)

  • BFS 알고리즘
    [begin, end)

const push = (item) => {
  stack[size] = item;
  size += 1
}

const pop = () => {
  stack[0] = 0;
  start += 1
}

양쪽 끝에서만 자료를 넣고(push) 양쪽 끝에서만 뺄 (pop) 수 있는 자료구조

push_front
push_back
pop_front
pop_back

0개의 댓글