Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C Homework givemecode
I have made this program for my assignment plzz check this and correct the errors i have to submit it latest by 12:00am
 

 

 
#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 10-Dec-12 2:55am
Edited 10-Dec-12 4:38am
v4
Comments
Alan N at 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.
Member 9505466 at 10-Dec-12 9:10am
   
i tried my best to do plzz help me out of this !
Richard MacCutchan at 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 at 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 at 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
joshrduncan2012 at 10-Dec-12 9:13am
   
You need to show some effort as to debugging before we can help you. We will not do the work for you.
OriginalGriff at 10-Dec-12 9:34am
   
We do not know what it is supposed to do, much less how well it does it!
But, a few quick bits:
1) Take out commented-out code - if it's if not used, it doesn't belong in there.
2) Comment your code! Functions need headers to describe them, and the code within them needs explanation.
3) Don't use single character variable names - use meaningful names that describe what you use the variable for.
4) "else" means just that. So you don't need to say:
if (a == b) { ... }
else
if (a != b) {...}
because the second condition is implied by the else.
if (a == b) { ... }
else {...}
Is clearer, and less code.
ryanb31 at 10-Dec-12 10:49am
   
What are the errors?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Have a lot of problem~~~
 
check syntax problem at first.
  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100