Thread: plz answer

  1. #1
    Registered User
    Join Date
    May 2013
    Location
    Alexandria, Egypt, Egypt
    Posts
    8

    plz answer

    plz can any one to tell me how to make 5+3*4/2 in a binary search tree in c (with code)
    Last edited by Radwa; 05-11-2013 at 05:12 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What do you understand by "make 5+3*4/2 in a binary search tree"? I mean, it sounds like you want a syntax tree instead.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2013
    Location
    Alexandria, Egypt, Egypt
    Posts
    8
    i want to understand how i can do it

  4. #4
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    in c (with code)
    You mean you want us to provide the code for you?
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  5. #5
    Registered User
    Join Date
    May 2013
    Location
    Alexandria, Egypt, Egypt
    Posts
    8
    yes plz

  6. #6
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    what are the terms of the contract?
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  7. #7
    Registered User
    Join Date
    May 2013
    Location
    Alexandria, Egypt, Egypt
    Posts
    8
    What does this mean؟

  8. #8
    Registered User
    Join Date
    May 2013
    Location
    Alexandria, Egypt, Egypt
    Posts
    8
    plz can anyone to help me i need it too much

  9. #9
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    No. The "Give meh da codez" approach does not work here.
    We have zero interest in simply doing your work for you.
    You will get nothing from us without posting a serious attempt at this.

    Edit: Actually I take that back, make it "... get nothing positive without ..."; you may of course receive some negative comments.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  10. #10
    Registered User
    Join Date
    May 2013
    Location
    Alexandria, Egypt, Egypt
    Posts
    8
    plz can anyone to help me i need it too much
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    typedef char EType;
    typedef struct tnode
    {
        EType data;
        char a[9];
        struct tnode* left;
        struct tnode* right;
    }tnode;
    typedef struct tnode* BTREE;
    tnode* insertBST (BTREE T,char x)
    {
        int i;
        int a[i];
        tnode* tmpcell;
        tmpcell=(tnode*)malloc(sizeof(tnode));
        if(tmpcell==NULL)
        {
            printf("out of space");
            return tmpcell;
        }else
        {
    
            tmpcell->data=x;
            tmpcell->left=tmpcell->right=NULL;
        }
        if(T==NULL)
            T=tmpcell;
        else if(x<T->data)
            T->left=insertBST(T->left,x);
        else if(x>T->data)
            T->right=insertBST(T->right,x);
    
    
        return T;
    }
    void show_node (BTREE T)
    {
    
        printf("%c\n",T->data);
    }
    int tree (char a[9])
    {BTREE T;
    int i,x;
    for( i=0;i>9;i++){
        a[i]=insertBST(T,x);
    
           return a[9];
    }
    }
    void inorder (BTREE T)
    {
         if(T!= NULL)
        {
         inorder(T->left);
         show_node(T);
         inorder(T->right);
         }
    }
    void postorder (BTREE T)
    {
        if(T!= NULL)
        {
         postorder(T->left);
         postorder(T->right);
         show_node(T);
         }
    }
    void preorder (BTREE T)
    {
        if(T!=NULL)
        {
            show_node(T);
            preorder(T->left);
            preorder(T->right);
        }
    }
    
    
    int main (void)
    {
        char a[9];
        BTREE T1,T2,T3,T4;
        T1=T2=T3=NULL;
        T1=insertBST(T1,1);
        T1=insertBST(T1,2);
        T1=insertBST(T1,0);
        T1=insertBST(T1,8);
        printf("\npreordar traverse\n");
        preorder(T1);
        printf("\nPostorder Traverse:\n");
        Postorder(T1);
        printf("\nInorder Traverse:\n");
        Inorder(T1);
    }

  11. #11
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by Radwa View Post
    plz can anyone to help me i need it too much
    You could start with correcting all the warnings/errors the compiler gives you:
    Code:
    $ gcc -Wall -Wextra -lm foo.c
    foo.c: In function ‘insertBST’:
    foo.c:16:9: warning: unused variable ‘a’ [-Wunused-variable]
    foo.c: In function ‘tree’:
    foo.c:48:9: warning: assignment makes integer from pointer without a cast [enabled by default]
    foo.c: In function ‘main’:
    foo.c:94:5: warning: implicit declaration of function ‘Postorder’ [-Wimplicit-function-declaration]
    foo.c:96:5: warning: implicit declaration of function ‘Inorder’ [-Wimplicit-function-declaration]
    foo.c:85:20: warning: unused variable ‘T4’ [-Wunused-variable]
    foo.c:84:10: warning: unused variable ‘a’ [-Wunused-variable]
    foo.c:97:1: warning: control reaches end of non-void function [-Wreturn-type]
    foo.c: In function ‘tree’:
    foo.c:52:1: warning: control reaches end of non-void function [-Wreturn-type]
    foo.c: In function ‘insertBST’:
    foo.c:16:5: warning: ‘i’ is used uninitialised in this function [-Wuninitialized]
    foo.c: In function ‘tree’:
    foo.c:48:19: warning: ‘x’ may be used uninitialised in this function [-Wuninitialized]
    foo.c:48:19: warning: ‘T’ may be used uninitialised in this function [-Wuninitialized]
    /tmp/ccuRngGr.o: In function `main':
    foo.c:(.text+0x2c0): undefined reference to `Postorder'
    foo.c:(.text+0x2d8): undefined reference to `Inorder'
    collect2: ld returned 1 exit status
    You should also ask specific questions instead of dumping your code here and hoping that someone will rewrite it.

    Bye, Andreas

  12. #12
    Registered User
    Join Date
    May 2013
    Location
    Alexandria, Egypt, Egypt
    Posts
    8
    I correct all errors but i can't connect array index to be a pointer to the data inside the node can any one to help me in this problem

  13. #13
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    array index to be a pointer to the data
    Do you mean the element of the array to be a pointer to the data? I say this because you should know that the index of an array can only be a postive integer value
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  14. #14
    Registered User
    Join Date
    May 2013
    Location
    Alexandria, Egypt, Egypt
    Posts
    8
    imean to put data of the tree node in a array

  15. #15
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    hmmm - i cant see how you got to the code above and yet cannot tackle that problem? Anyway from what i can gather i think you need to declare an array of your nodes - that is to say, each element of your array will contain an instance of your tnode struct or whatever
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 08-13-2012, 03:19 AM
  2. Help with comparing answer to math problem and user's answer
    By Jake Garbelotti in forum C Programming
    Replies: 6
    Last Post: 07-20-2012, 10:12 PM
  3. !!Everybody *has* to answer this one!!
    By abh!shek in forum A Brief History of Cprogramming.com
    Replies: 101
    Last Post: 02-07-2008, 08:16 PM
  4. Where Can I Get The Answer?
    By MartinLiao in forum C++ Programming
    Replies: 3
    Last Post: 07-23-2004, 01:19 PM
  5. Please answer this
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 02-25-2004, 11:43 AM