דחיפה
שיעור 4 מתוך 13 בקורס מחסנית – סדרת מבני נתונים #1 של Coddy.
אתגר
קלהוסיפו ל־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
תרגלו בעצמכם: קומפיילר C אונליין