Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
1.00/5 (6 votes)
See more:
I have made this program for my assignment plzz check this and correct the errors i have to submit it latest by 12:00am





C++
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

struct node
{
    int element;
    struct node* left;
    struct node* right;
};

typedef struct node* ptrtonode;
typedef ptrtonode searchtree;
typedef ptrtonode position;
/*
struct treenode
{
    int Element;
    treenode *Left;
    treenode *Right;
};

typedef struct treenode *PtrToNode;
typedef struct *PtrToNode searchtree;
typedef struct *PtrToNode Position;

searchtree tree(int x,searchtree T);
void preorder(searchtree T);

*/

searchtree tree(int x,searchtree T);
void preorder(searchtree T);

int main()
{
    int T=NULL;
    
    
    freopen("inp.txt","r",stdin);
    //  freopen("out.txt","w",stdout);
    int  c,i=0;
    int array[100];
    
    while((scanf("%d",&c))!=EOF)
    {
        array[i++]=c;
        //printf("%d",c);
        tree(c,T);
        
    }
    
    preorder(T);
    return 0;
}





searchtree tree(int x,searchtree T)
{

    //searchtree T;
    if(T==NULL)
    {
        T=malloc(sizeof(struct node));
        T->element=x;
        T->left=NULL;
        T->right=NULL;
    }
    
    else
    if(T!=NULL)
    {
    
        if(x<t->element)
        {
            T->left=tree(x,T->left);
        }
        
    else
    if(x>T->right)
    {
        T->right=tree(x,T->right);
    }
    
    }
    
}
void preorder(searchtree T)
{

if(T!=NULL)
    {
        printf("%d",T->element);
        
        preorder(T->left);
        preorder(T->right);
    }
    
}
Posted
Updated 10-Dec-12 4:38am
v4
Comments
Alan N 10-Dec-12 9:01am    
Sorry mate you're too late. It's already 1400 here! On a more serious note, why not test your code and see if it performs as expected.
Aftab Gikian 10-Dec-12 9:10am    
i tried my best to do plzz help me out of this !
Richard MacCutchan 10-Dec-12 9:28am    
How can we check it when we don't know what it is supposed to do? Try building it so you can at least fix the basic errors.
nv3 10-Dec-12 9:29am    
If you have already problems with an easy assignment like this, what will you do when you will be working on real software?
Sergey Alexandrovich Kryukov 10-Dec-12 17:11pm    
No; it's not very likely that anyone would look at your code before you explain what you tried to achieve, what it was supposed to do, what did you observer instead and why do you think this behavior is wrong.

Also, did you execute it under debugger?
--SA

1 solution

Have a lot of problem~~~

check syntax problem at first.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900