How to display BST tree?

Hello,
I have a problem witch dislay BST tree in Windows console. Maybe somone have idea or ready solution how to do this? Thanks for any help.
Here is my BST implemantation:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <cstdlib>
#include <iostream>

using namespace std;

struct wezel                                                               
{
       int liczba;
       struct wezel *lewy;
       struct wezel *prawy;
} *root;
struct wezel *nowy_wezel(int var)                                             
{
      struct wezel *m_wezel = new(struct wezel);
      m_wezel->liczba = var;
      m_wezel->lewy = NULL;
      m_wezel->prawy = NULL;
      return(m_wezel);
}
struct wezel *dodaj_el(struct wezel *n_wezel, int var)               
{
              if(n_wezel==NULL)
              {
                  return(nowy_wezel(var));   
                 
              }
              else
              {
                  if(var <= n_wezel->liczba)
                         {                                   
                         n_wezel->lewy = dodaj_el(n_wezel->lewy, var); 
                         
                         }
                  else
                         {       
                         n_wezel->prawy = dodaj_el(n_wezel->prawy, var); 
                       
                         }
              }
                         
              return(n_wezel);
             
}
void dislay(struct *p_root)
{
   //?????????
}
int main(int argc, char *argv[])
{ 
    root=dodaj_el(root,6);
    root=dodaj_el(root,3);
    root=dodaj_el(root,8);
    root=dodaj_el(root,1); 
    root=dodaj_el(root,9);
   display(root); //????????
   
  cout << "\n";
    system("PAUSE");
    return EXIT_SUCCESS;
}
Last edited on
Please:

1
2
3
4
5
6
7
8
9
void display(wezel *p_root)
{
        if ( p_root != NULL )
        {
                display(p_root->lewy);
                cout << p_root->liczba << " ";
                display(p_root->prawy);
        }
}


Ps. Pozdro dla kolegi z Polski:)
Topic archived. No new replies allowed.