Originally Posted by
anduril462
That looks about right. Test it. If it gives you trouble, post back here with the input you used that failed and a description of the problem.
Here are the errors
prel.c: In function ‘displayBST’:
prel.c:53: warning: passing argument 1 of ‘padding’ makes integer from pointer without a cast
prel.c:13: note: expected ‘char’ but argument is of type ‘char *’
prel.c:58: warning: passing argument 1 of ‘padding’ makes integer from pointer without a cast
prel.c:13: note: expected ‘char’ but argument is of type ‘char *’
Here is my code:
Code:
#include <stdio.h>
#include<stdlib.h>
typedef struct bt_{
int value;
struct bt_ *right;
struct bt_ *left;
}BST;
BST* insert(BST* root, int value);
void printTree(BST* root);
void displayBST(BST* root, int depth);
void padding(char toPrint, int numTimes);
int main(){
int value;
BST *new_BST;
while(value != -1){
printf("\nEnter a number to put into the tree");
scanf("%d", &value);
new_BST = insert(new_BST, value);
}
printTree(new_BST);
}
BST* insert(BST* root, int value){
if(root != 0){
if(value < root->value)
root->left = insert(root->left, value);
else if( value > root->value)
root->right = insert(root->right, value);
return root;
}
BST *n = (BST*) malloc(sizeof(BST));
n->value = value;
n->left = n->right = 0;
return n;
}
void printTree(BST* root)
{
displayBST(root,0);
void displayBST(BST* root, int depth){
if(root==NULL)
{
padding("''", depth);
printf("-\n");
return;
}
displayBST(root->left,depth+4);
padding("'' ", depth);
printf("%d\n", root->value);
displayBST(root->right, depth+4);
}
void padding(char toPrint, int numTimes)
{
int i;
for(i=0; i < numTimes; i++)
printf("%c", toPrint);
}
thanks