הוצאה מהתור
שיעור 5 מתוך 12 בקורס תור – סדרת מבני הנתונים #2 של Coddy.
אתגר
קלהוסף ל-Queue מתודה בשם dequeue שאינה מקבלת קלט ומסירה את הפריט שבחזית התור.
תזכורת! זהו מבנה נתונים מסוג ראשון נכנס, ראשון יוצא (FIFO).
נסו בעצמכם
#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();
}
}
for (int item : q.items) {
std::cout << item << std::endl;
}
return 0;
}
כל השיעורים ביחידה תור – סדרת מבני הנתונים #2
תרגלו בעצמכם: קומפיילר C אונליין