push
Coddy의 스택 - 자료구조 시리즈 #1 코스 레슨. 13개 중 4번째.
챌린지
쉬움Stack에 정수를 인자로 받아 스택의 맨 위에 추가하는 push 메서드를 추가하세요.
직접 해보기
#include <stdio.h>
#include <string.h>
#include "stack.h"
int main() {
Stack stack;
Stack_init(&stack);
char cmd[16];
while (scanf("%15s", cmd) == 1) {
if (strcmp(cmd, "push") == 0) {
int x;
scanf("%d", &x);
Stack_push(&stack, x);
}
}
for (int i = 0; i < stack.size; i++) {
printf("%d\n", stack.elements[i]);
}
return 0;
}
스택 - 자료구조 시리즈 #1의 모든 레슨
직접 연습해 보세요: 온라인 C 컴파일러