#include #include using namespace std; template struct Node { T data; Node *next; }; template void addFront(Node*& head, T data) { head = new Node{data, head}; } template void addBack(Node*& head, T data) { if (head == nullptr) addFront(head, data); else { Node* tmp = head; while (tmp->next != nullptr) tmp = tmp->next; tmp->next = new Node{data, nullptr}; } } template void printList(const Node* h) { std::cout << "[ "; while (h != nullptr) { std::cout << h->data << " "; h = h->next; } std::cout << "]\n"; } template void deleteList(Node*& h) { while (h != nullptr) { Node* t = h->next; delete h; h = t; } } int main() { // "jakisnapis"s bedzie literalem typu std::string using namespace std::literals; Node* headI{nullptr}; addBack(headI, 3); addBack(headI, 4); addFront(headI, 2); addFront(headI, 1); printList(headI); deleteList(headI); Node* headS{nullptr}; addBack(headS, "kiery"s); addBack(headS, "piki"s); addFront(headS, "kara"s); addFront(headS, "trefle"s); printList(headS); deleteList(headS); }