סוף התור
שיעור 7 מתוך 12 בקורס תור – סדרת מבני הנתונים #2 של Coddy.
אתגר
קלהוסיפו ל־Queue מתודה בשם rear שאינה מקבלת קלט ומחזירה את הפריט האחרון בתור (הפריט שהוכנס אחרון לתור).
נסו בעצמכם
#include <iostream>
#include <sstream>
#include <string>
#include "queue.h"
int main() {
Queue q;
std::string line;
while (std::getline(std::cin, line)) {
std::istringstream iss(line);
std::string cmd;
if (!(iss >> cmd)) continue;
if (cmd == "enqueue") {
int x; iss >> x; q.enqueue(x);
}
if (cmd == "dequeue") {
q.dequeue();
}
if (cmd == "front") {
std::cout << q.front() << std::endl;
}
if (cmd == "rear") {
std::cout << q.rear() << std::endl;
}
}
return 0;
}
כל השיעורים ביחידה תור – סדרת מבני הנתונים #2
תרגלו בעצמכם: קומפיילר C אונליין