Menu
Coddy logo textTech

push

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

challenge icon

챌린지

쉬움

Stack에 정수를 인자로 받아 스택의 맨 위에 추가하는 push 메서드를 추가하세요. 

직접 해보기

#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);
        }
    }
    for (int element : stack.elements) {
        std::cout << element << std::endl;
    }
    return 0;
}

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