Labs ICT
Pro Login

Queue

C++ Queue

std::queue follows the FIFO (First In, First Out) principle. Elements are added at the back with push() and removed from the front with pop(). Access the front element with front() and the back with back(). Queues model real-world lines and are used in BFS and task scheduling.

#include <iostream>
#include <queue>

int main() {
    std::queue<std::string> q;
    q.push("first");
    q.push("second");
    q.push("third");
    std::cout << "Front: " << q.front() << "\n";
    q.pop();
    std::cout << "Front after pop: " << q.front();
    return 0;
}
Try it Yourself →