Witam, mam do napisania program na uczelnie, wyswietlajacy drzewo z randomowa iloscia galezi, liczb podawanych przez uzytkowania. Nie moge korzystac z tablic, ani z zadnych innych bibliotek niz podane ponizej. **Program prawie dziala z wyjatkiem tego ze koncowo wyswietla ostatnia podana liczbe. **

 #include <iostream>
#include <cstdlib>
#include <time.h>

using namespace std;

struct wezel {
    int value;
    wezel * right;
};

void WstawDane( wezel * r, int x )
{
    cout << "wstawiany:" << x << endl;
    if( r == NULL )
    {
        wezel * nowy = new wezel;
        nowy->value = x;
        nowy->right = NULL;
        r = nowy;
    }
    else
         WstawDane( r->right, x );
    
}


void WyswietlDrzewo( wezel * r, int x, int ile )
{
    
    srand( time( NULL ) );
    int licznik = 0;
    
    while( licznik < ile )
    {
        int p = rand() % 7 + 1;
        for( int i = 0; i < 1; i++ ) {
            cout <<( r->right, x ) << endl;
            licznik += 1;
            if( licznik >= ile )
                 exit( 1 );
            
        }
        
        int q = 0;
        for( int j = 0; j < p && j < ile; j++ )
        {
            int n = rand() % 3 + 1;
            for( int w = 0; w < n; w++ ) {
                if( j > 0 ) { cout << "|"; }
                if( j > 0 )
                {
                    for( int m = 0; m < q; m++ ) {
                        cout << "     "; }
                }
                
                cout << "|" << "----" <<( r->right, x ) << endl;
                
                licznik += 1;
                if( licznik >= ile )
                     exit( 1 );
                
            } q++;
        }
    }
}


int main( void )
{
    int ile;
    cout << "Podaj ilosc wierzcholkow, ktore chcesz umiescic w drzewie: " << endl;
    cin >> ile;
    int wstawiany;
    wezel * root = NULL;
    for( int i = 0; i < ile; i++ ) {
        cout << "w" << i + 1 << ": ";
        cin >> wstawiany;
        WstawDane( root, wstawiany );
    }
    
    cout << endl << endl << endl << "Twoje drzewo wyglada nastepujaco: " << endl << endl;
    
    cout << "PRÓBA!" << endl;
    cout << "root:" << root << endl;
    cout << "wstawiany:" << wstawiany << endl;
    cout << "ile:" << ile << endl;
    
    WyswietlDrzewo( root, wstawiany, ile );
    
    cout << endl << endl;
    
    system( "PAUSE" );
    return 0;
}