#include using namespace std; class Item; class List { public: Item * first; List() : first (nullptr) { } void insert (int k0, string v0); void insertLast (int k0, string v0); void print(); }; class Item { public: int key; string value; Item * next; // Item(); Item(int key0, string value0); }; void List::insert (int k0, string v0) { Item * p = new Item (k0, v0); p->next = first; first = p; } void List::insertLast(int k0, string v0) { Item* p = new Item(k0, v0); p->next = nullptr; if (first == nullptr) { first = p; } else { Item* current = first; while (current->next != nullptr) { current = current->next; } current->next = p; } } void List::print() { Item * p = first; if (p == nullptr) { cout << "Prazdne..." << endl; } else { while (p != nullptr) { cout << p->key << ":" << p->value << endl; p = p->next; } } } // Item::Item (): // key(0), value(""), next(nullptr) // {} Item::Item (int key0, string value0) : key(key0), value(value0), next(nullptr) { } int main() { List a; a.insert(1, "abc"); a.insert(2, "def"); a.insert(3, "klm"); a.insertLast(4, "xyz"); a.print(); }