Menu
Coddy logo textTech

ראש התור

שיעור 6 מתוך 12 בקורס תור – סדרת מבני הנתונים #2 של Coddy.

challenge icon

אתגר

קל

הוסף ל-Queue מתודה בשם front שאינה מקבלת קלט ומחזירה את הפריט הקדמי בתור.

נסו בעצמכם

#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;
        }
    }
    return 0;
}

כל השיעורים ביחידה תור – סדרת מבני הנתונים #2

תרגלו בעצמכם: קומפיילר C אונליין