added print, need testing

This commit is contained in:
2026-03-15 21:37:15 -06:00
parent 8792eb3159
commit 3dd365012c

View File

@@ -5,6 +5,7 @@
#include <expected>
#include <format>
#include <new>
#include <print>
#define DEFAULT_STACK_SIZE 4
@@ -71,6 +72,7 @@ StackErr Stack<T>::push(T value) {
delete[] this->data;
this->data = tmp;
this->cap = new_capacity;
}
this->data[this->len] = value;
@@ -104,6 +106,7 @@ std::expected<T, StackErr> Stack<T>::pop() {
delete[] this->data;
this->data = tmp;
this->cap = new_capacity;
}
return std::expected(return_val);
@@ -119,4 +122,24 @@ std::expected<T, StackErr> Stack<T>::peek() {
return std::expected(this->data[this->len - 1]);
}
template <typename T>
requires std::formattable<T, char>
void Stack<T>::print() {
std::println("Stack:");
std::println("Length: {}.", this->len);
std::println("Capacity: {}.", this->cap);
std::println("{:^20}", "Datos");
std::println("{:^20}", "|");
std::println("{:^20}", "v");
for (int i = 0; i < this->cap; i++) {
if (i < this->len) {
std::println("{:^20}", this->data[i]);
} else {
std::println("{:^20}", "NULL");
}
}
}
#endif // !ST