#include <iostream>
 
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();
}
 
seznam2020.txt · Last modified: 2020/02/25 12:32 by 147.32.8.115
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki