Menu
Coddy logo textTech

pop

Coddy의 스택 - 자료구조 시리즈 #1 코스 레슨 — 13개 중 6번째.

challenge icon

챌린지

쉬움

Stack에 인수를 받지 않는 pop이라는 메서드를 추가하세요. 이 함수는 스택의 맨 위에 있는 정수를 제거하고 그 값을 반환합니다. 

직접 해보기

#include <iostream>
#include <sstream>
#include <string>
#include "stack.h"

int main() {
    Stack stack;
    std::string line;
    while (std::getline(std::cin, line)) {
        std::istringstream iss(line);
        std::string cmd;
        if (!(iss >> cmd)) continue;
        if (cmd == "push") {
            int x; iss >> x; stack.push(x);
        }
        else if (cmd == "top") {
            std::cout << stack.top() << std::endl;
        }
        else if (cmd == "pop") {
            std::cout << stack.pop() << std::endl;
        }
    }
    return 0;
}

스택 - 자료구조 시리즈 #1의 모든 레슨