#include <iostream>
using namespace std;
 
struct Item
{
    string name;
    int r, g, b;
    Item* next;
};
 
void vypis(Item* p)
{
    if (p == nullptr)
    {
        cout << "Seznam je prazdny";
    }
    else
    {
        while (p != nullptr)
        {
            cout << p->name << endl;
            p = p->next;
        }
    }
}
 
void vytiskni(Item* p)
{
    if (p != nullptr)
    {
        vytiskni (p->next);
        cout << p->name << endl;
    }
}
 
void hledej(Item* p, string text)
{
    while (p != nullptr && p->name != text)
    {
        p = p->next;
    }
 
    if (p != nullptr) {
        cout << "nalezeno: " << p->name << ", "
            << p->r << ", " << p->g << ", " << p->b << endl;
    }
    else
        cout << "nenalezeno" << endl;
}
 
void vloz_na_zacatek( Item* & p, string n0, int r0, int g0, int b0)
{
    Item* t = new Item;
    t->name = n0;
    t->r = r0;
    t->g = g0;
    t->b = b0;
    t->next = p; // projeni noveho prvniho prvku s puvodnim prvnim prvkem
    p = t; // zmenit ukazatel na novy prvni prvek
}
 
Item* first = nullptr;
 
int main()
{
    Item* a = new Item;
    a->name = "cervena";
    a->r = 255;
    a->g = 0;
    a->b = 0;
 
    Item* b = new Item;
    b->name = "modra";
    b->r = 0;
    b->g = 0;
    b->b = 255;
 
 
    Item* c = new Item;
    c->name = "zelena";
    c->r = 0;
    c->g = 255;
    c->b = 0;
 
    first = a;
    a->next = b;
    b->next = c;
    c->next = nullptr;
 
    Item* last = first;
    while (last->next != nullptr)
    {
        last = last->next;
    }
 
 
    cout << "a: " << a->name << endl;
    cout << "b: " << b->name << endl;
    cout << "c: " << c->name << endl;
    vloz_na_zacatek(first, "zluta", 255, 128, 0);
    cout << "first: " << first->name << endl;
    cout << "second: " << first->next->name << endl;
    cout << "last:" << last->name << endl;
 
    //c->next = a;
    vypis(first);
    hledej(first, "oranzova");   
    vytiskni(first);
 
    cout << "O.K.";
}
 
ukazatele2019.txt · Last modified: 2019/10/31 15:09 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