front
Урок 6 из 12 курса Очередь — Серия «Структуры данных» №2 на Coddy.
Задание
ЛегкоДобавьте в Queue метод с именем front, который не принимает никаких аргументов и возвращает первый (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;
}