Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8576721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:59:20+00:00 2026-06-11T19:59:20+00:00

I need to figure out how to create an arithmetic expression tree. I can

  • 0

I need to figure out how to create an arithmetic expression tree.

I can create simple binary tree using just set of numbers. There is a code example below:

This is simple node that for my tree.

typedef struct _node {
    int key;
    struct _node *left, *right;
} node;

This is how I add new node to my binary tree:

node* add_tree(node *root, int val) {    
    if(NULL == root) {
        root = crnode(val);
    }    
    if (val < root->key) {
        if (NULL == root->left) {
            root->left = crnode(val);
        }
        else {
            add_tree(root->left, val);
        }
    }

    if (val > root->key) {
        if (NULL == root->right) {
            root->right = crnode(val);
        }
        else {
            add_tree(root->right, val);
        }
    }    
    return root;
}

This is main function and steps how I add new number to tree:

int main(int argc, const char * argv[])
    {    
        node *tree = add_tree(NULL, 5);
        tree = add_tree(tree, 6);
        tree = add_tree(tree, 7);
        tree = add_tree(tree, 3);
        return 0;
    }

My question is: how to transform this code that I can using not just a number but and operator (e.g + – / *).

For example I need to transform an expression 5 * (10 – 5) + 6 * 4 to tree. How can I make it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:59:22+00:00Added an answer on June 11, 2026 at 7:59 pm

    A node in your expression is one of two things: an operator or a value. So you need to delineate. There are several ways to do this, but since this is homework I’m inclined to be a little cagey and let you work something out using the programming concepts you have learned thus far.

    So I decided to help you by showing what your tree might look like if you had your nodes working:

          +
         / \
        /   \
       /     \
      *       *
     / \     / \
    5   -   6   4
       / \
      10  5
    

    You might want to drop the notion of ‘building a tree’, and instead think of it as ‘constructing an expression’. It could be what’s holding you back. You might end up with some functions that are used like this:

    node *expr = subtract(value(10), value(5));
    

    That builds a part of the tree. See what’s going on? =)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to figure out a way to set ValidateRequest at model...I understand that
So i need to figure out how i can get a record count value
Can't figure out how to use bbp_get_reply_author_role(), and i really need it, returns an
I need to figure out the best way to create a url to a
I need to figure out a way to add CRUD (Create, Read, Update and
I need to figure out a way to insert a record with a java.util.Date
I need to figure out the size of a remote file before I download
I understand that I need to figure out my own homework, but seeing that
From the following HTML I need to figure out which List tag has class
I have a piece of code where I need to figure out if a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.