push
Coddy'nin Stack - Veri Yapıları Serisi #1 kursunda ders 4 / 13.
Görev
KolayStack sınıfına, bir tam sayı alan ve bu tam sayıyı yığının en üstüne ekleyen push adında bir metot ekleyin.
Kendin dene
#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;
}