added print with indications and all, based on a design for another proyect
This commit is contained in:
@@ -36,7 +36,7 @@ public:
|
|||||||
|
|
||||||
std::expected<T, QueueErr> dequeue();
|
std::expected<T, QueueErr> dequeue();
|
||||||
|
|
||||||
void display();
|
void print();
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@@ -147,4 +147,34 @@ std::expected<T, QueueErr> Queue<T>::peek() {
|
|||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
requires std::formattable<T, char>
|
||||||
|
void Queue<T>::print() {
|
||||||
|
if (this->len == 0) {
|
||||||
|
std::println("Queue is empty.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::println("Lenght: {}", this->len);
|
||||||
|
std::println("Capacity: {}", this->cap);
|
||||||
|
for (uint64_t i = 0; i < this->cap; i++) {
|
||||||
|
if (this->tail == this->head) {
|
||||||
|
std::println("H/T --->");
|
||||||
|
} else if (this->tail == i) {
|
||||||
|
std::println("Tail--->");
|
||||||
|
} else if (this->head == i) {
|
||||||
|
std::println("Head--->");
|
||||||
|
} else {
|
||||||
|
std::println("|{:^20}|", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t dist = (i + this->cap - this->tail) % this->cap;
|
||||||
|
if (dist < this->len) {
|
||||||
|
std::println("|{:^20}|", this->data[i]);
|
||||||
|
} else {
|
||||||
|
std::println("|{:^20}|", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif // !QUEUE_H
|
#endif // !QUEUE_H
|
||||||
|
|||||||
Reference in New Issue
Block a user