#pragma once /** * Representation of a task in the system */ struct Task { const char *name; int id; int priority; int burst; }; #ifdef __cplusplus template struct Queue { struct Item { Item(T *p_node) : node(p_node) {} T *node; Item *next = nullptr; [[nodiscard]] bool operator==(const T *other) const { return node == other; } }; ~Queue() noexcept { for (auto *it = head; it != nullptr;) { auto *current = it; it = it->next; delete current->node; delete current; } } /// Insert item at the end of the queue void insert(T *item) { if (head == nullptr) { head = new Item(item); tail = head; } else { tail->next = new Item(item); tail = tail->next; } } void remove(T *item) { if (head == nullptr) return; if (item == head->node) { auto *it = head; head = head->next; if (*tail == item) tail = nullptr; delete it; return; } Item *prev = nullptr; for (auto *it = head; it != nullptr; it = it->next) { if (it->node == item) { if (prev) { prev->next = it->next; } if (tail == it) { tail = prev; } delete it; return; } prev = it; } } Item *head = nullptr; Item *tail = nullptr; }; #endif