pop
Coddy'nin Stack - Veri Yapıları Serisi #1 kursunda ders 6 / 13.
Görev
KolayStack sınıfına, hiçbir argüman almayan pop adında bir metot ekleyin; bu fonksiyon yığının en üstündeki tam sayıyı kaldıracak ve onu döndürecektir.
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);
}
else if (cmd == "top") {
std::cout << stack.top() << std::endl;
}
else if (cmd == "pop") {
std::cout << stack.pop() << std::endl;
}
}
return 0;
}