#ifndef old_h #define old_h #include // malloc, free #include // std::optional template class stack { public: ~stack() { while (pop()); } void push(T t) { struct node *new_node = (struct node *)malloc(sizeof(struct node)); new_node->next = head; new_node->data = t; head = new_node; } std::optional pop() { if (head != NULL) { struct node *copy = head; head = copy->next; T data = copy->data; free(copy); return std::optional(data); } else { return std::nullopt; } } private: struct node { struct node *next; T data; }; struct node *head = NULL; }; #endif // old_h