스택

· Major/C&C++
1. 스택 - 선입 후출 구조 - 맨 처음에 들어간 원소를 top라고 지정한다. 1) 배열 ⓐ 구조체 선언 #define SIZE 1000 typedef struct { int key; // 다른필드 }element; element stack[SIZE]; ⓑ push int top = 0; void push(int* top_ptr, element item) { if (*top_ptr >= SIZE) { printf("스택이 다 찼습니다."); } stack[(*top_ptr)++] = item; } ⓒ pop void pop(int* top_ptr) { if (*top_ptr == 0) { printf("스택이 비어있습니다."); } stack[(*top_ptr)--]; } * push와 pop 모두 매..
BeNI
'스택' 태그의 글 목록