#include <iostream>
using namespace std;
struct Cell
{
int data;
Cell* left;
Cell* right;
};
int Add(int step, int data, Cell *&ptr)
{
bool dir = 0;
step--;
if (!&*ptr)
{
ptr = new Cell;
//cout << ptr << endl;
ptr->data = 0;
ptr->left = 0;
ptr->right = 0;
}
if (!ptr->data && step)
{
cout << "leftlink " << ptr <<endl;
dir = Add(step, data, ptr->left);
}
if (ptr->data)
{
cout << "DIR" << endl;
return 1;
}
if (!ptr->data && step == 0)
{
cout << "data" << endl;
ptr->data = data;
return 0;
}
if (dir && !ptr->data && step)
{
cout << "rightlink " << ptr << " " << dir << endl;
Add(step, data, ptr->right);
}
//cout << "ЕСЛИ РАСКОМЕНТИТЬ ЭТУ СТРОЧКУ ТО НИХУЯ НЕ РАБОТАЕТ ";
}
int main()
{
Cell* root = 0;
Add(2, 1, root);
cout << endl;
Add(4, 10, root);
cout << endl;
Add(4, 12, root);
cout << endl;
Add(5, 2, root);
cout << endl;
Add(5, 11, root);
cout << endl;
Add(5, 31, root);
cout << endl << root->right->right->right->left->data;
}