#include "stdafx.h"
 
#include <stdlib.h>
#include <iostream>
#include <cassert>
#include <string>
 
using namespace std;
 
struct T
{
    string data;
    int r, g, b;
    T* prev;
    T* next;
};
 
T* first;
T* last;
 
T*create (string jmeno, int r0, int g0, int b0)
{
    T*result = new T;
    result->data = jmeno;
    result->r = r0;
    result->g = g0;
    result->b = b0;
    result->prev = nullptr;
    result->next = nullptr;
 
    return result;
}
 
void place (T* prvek)
{
    if (first == nullptr)
    {
        last = prvek;
        first = prvek;
        prvek->prev = nullptr;
        prvek->next = nullptr;
    }
    else
    {
        last->next = prvek;
        prvek->prev = last;
        last = prvek;
        prvek->next = nullptr;
    }
 
}
 
void placeTo (T* prvek, T* ref)
{
    prvek->prev = ref;
    prvek->next = ref->next;
    if (ref->next != nullptr) {
        ref->next->prev = prvek;
    }
    else {
        last = prvek;
    }
    ref->next = prvek;
}
 
void Check ()
{
    if (first == nullptr )
    {
        assert (last == nullptr);
    }
    else
    {
        assert (last != nullptr);
 
        T* prv = first;
        int count = 0;
 
        while (prv != nullptr)
        {
            count++;
            prv = prv->next;
        }
 
 
        prv = last;
        while (prv != NULL)
        {
            count--;
            prv = prv->prev;
        }
 
        assert (count == 0);
    }
 
 
}
 
void print () {
    T* prv = first;
 
    while (prv != nullptr)
    {
        cout << prv->data << endl;
        prv = prv->next;
    }
}
 
int main()
{
    cout << "Zacatek" << endl;
    first = nullptr;
    last = nullptr;
    Check ();
 
    place (create ("neco", 128, 128, 128));
    Check ();
 
    place (create ("neco2", 128, 128, 128));
    Check ();
 
    placeTo (create ("neco3", 128, 128, 128), first);
    Check ();
 
    placeTo (create ("neco4", 128, 128, 128), last);
    Check ();
 
    print();
 
    system ("pause");
    return 0;
}
 
seznam2018a.txt · Last modified: 2018/02/20 10:45 by 147.32.8.110
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki