[Dev-C++] display tree (another one)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: chromatonus 7. <chr...@ho...> - 2002-02-18 01:09:37
|
hi, thank you for your previous help, but i have another problem...
I keep receiving this error and i don't know what it means:
passing `int' to argument 2 of `pic(node *, int *, int)' lacks a cast
Thank you for your help,
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
struct node
{
int data;
node *left, *right;
};
//================================ PROTOTYPES
==================================
int menu();
//postcondition: creates and displays a menu, returning the value of
choice
void create( node *&, int );
void insert_node(node *&, node*);
void pre( node* );
void in( node* );
void post( node* );
void pic( node*, int[63], int );
int two_exp(int);
int make_array( node* );
int size( node* );
int menu()
{
int choice;
cout<< "TREE EDITOR MENU OPTIONS" << "\n";
cout<< "1. Insert elements in Tree" << "\n";
cout<< "2. Display Tree in Prefix" << "\n";
cout<< "3. Display Tree in Infix" << "\n";
cout<< "4. Display Tree in Postfix" << "\n";
cout<< "5. Display Tree Diagram" << "\n";
cout<< "6. Balance Tree" << "\n";
cout<< "7. Exit";
gotoxy(1,10);
cout<< "choice? ";
cin>> choice;
return(choice);
}
//=============================== Main Program
=================================
int main()
{
node *root = NULL;
int choice, info, s;
choice = menu();
while( choice != 7 )
{
switch( choice )
{
case 1: gotoxy(1,12);
cout<< "input? ";
cin>> info;
node *stem;
create( stem, info );
insert_node(root, stem);
break;
case 2: gotoxy(1,15);
cout<< "Prefix: ";
pre( root );
break;
case 3: gotoxy(1,17);
cout<< "Infix: ";
in( root );
break;
case 4: gotoxy(1,19);
cout<< "Postfix: ";
post( root );
break;
case 5: clrscr();
s = size( root );
pic( root, make_array(root), s );
break;
case 6:
break;
}
gotoxy(1,10);
cout<< "choice? ";
cin>> choice;
}
}
void create( node *& stem, int info )
{
stem = new node;
stem->data = info;
stem->left = NULL;
stem->right = NULL;
}
void insert_node(node *&root, node *stem)
{
if(root == NULL)
{
root = stem;
}
else
{
if(stem->data < root->data)
insert_node(root->left, stem);
else
insert_node(root->right, stem);
}
}
void pre(node *root)
{
if( root != NULL )
{
cout<< root->data << " ";
pre( root->left );
pre( root->right );
}
}
void in(node *root)
{
if( root != NULL )
{
in(root->left);
cout<< root->data <<" ";
in(root->right);
}
}
void post(node *root)
{
if(root != NULL)
{
post(root->left);
post(root->right);
cout<< root->data <<" ";
}
}
int two_exp(int k)
{
int i, s = 1;
for(i=0; i<=k; i++)
s = 2*s;
return s;
}
int make_array( node* root )
{
int n = 0, array[63];
if( root != NULL )
{
array[n] = root->data;
n++;
pre( root->left );
pre( root->right );
}
return array[63];
}
int size( node* root )
{
int i = 0, array[63];
if( root != NULL )
{
array[i] = root->data;
i++;
pre( root->left );
pre( root->right );
}
return i;
}
//trying to display the tree in a visual form on the screen
void pic(node *root, int array[], int i)
{
int x=33, y=2, j, lev = 4;
node *track = new node;
track = root;
track->left = NULL;
track->right = NULL;
gotoxy(x,y);
cout<< array[0];
for(j=0; j<=i; j++)
{
while((track != NULL) && (array[j+1] < array[j]))
{
x = x-two_exp(lev);
y = 2*y;
gotoxy(x,y);
cout<< array[j+1];
track = track->left;
lev--;
}
while((track != NULL) && (array[j+1] >= array[j]))
{
x = x+two_exp(lev);
y = 2*y;
gotoxy(x,y);
cout<< array[j+1];
track = track->right;
lev--;
}
if((track = NULL) && (array[j+1] < array[j]) )
{
x = x-two_exp(lev);
y = 2*y;
gotoxy(x,y);
cout<< array[j+1];
track = root;
lev = 4;
}
if((track = NULL) && (array[j+1] >= array[j]) )
{
x = x+two_exp(lev);
y = 2*y;
gotoxy(x,y);
cout<< array[j+1];
track = root;
lev = 4;
}
}
}
P.S. any suggestions on how to "balance" the tree? (trying to display all
the same elements, but arrange them in such a way as to minimize the # of
levels in the tree) Thank you!
_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx
|