Menu
Coddy logo textTech

rear

Lekcja 7 z 12 w kursie Kolejka — struktury danych, seria nr 2 w Coddy.

challenge icon

Wyzwanie

Łatwy

Dodaj do Queue metodę o nazwie rear, która nie przyjmuje żadnych danych wejściowych i zwraca ostatni element kolejki (element, który został dodany do niej jako ostatni).

Spróbuj swoich sił

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

Wszystkie lekcje w sekcji Kolejka — struktury danych, seria nr 2

Poćwicz samodzielnie: Kompilator C online