강의

멘토링

로드맵

Inflearn Community Q&A

whiteleo960732's profile image
whiteleo960732

asked

Hong Jung-mo's C Programming: Learning by Doing (Appendix)

17.9 Stack Data Structure

스택 자료구조

Written on

·

245

0

스택 자료구조에 대해 조금 궁금증이 생겨서 질문 남깁니다.

연습 문제를 풀 때 pop

element Pop(Stack* stack)

{

if (IsEmpty(stack) == true)

{

element tempt = { -1 };

printf("Stack is Empty. Cannot remove\n");

return tempt; 

}

else

{

return stack->items[stack->top--];

}

}

이것을 구현 하는데 오랜 시간이 걸렸는데, 이유가 이미 쌓인 메모리를 아에 지우려고 시도해서 입니다. 그런데 코드를 보면 

stack->top 을 인덱스 처럼 이용해서 stack->top의 값만 바꾸어 주며 사실 저장된 값은 그대로 있어서 사용하지도 않는 값을 가지고 있는게 아닌가 하는 의문이 들었습니다.

앞에서 배운 linked-list의 경우는 free를 이용하여 메모리를 지워주는데 스택의 메모리는 계속 쌓여있는 것이 아닌가요?

c

Quiz

51% of people got it wrong. Give it a try!

When comparing arrays and linked lists, which data structure is more efficient for data insertion or deletion?

Array

Linked list

Stack

Q

Answer 1

0

honglab님의 프로필 이미지
honglab
Instructor

'스택'의 의미가 '쌓여있는 것'입니다.

whiteleo960732's profile image
whiteleo960732

asked

Ask a question