Question

NEED HELP IN C!! Answer in C programming language.

Question:

For the assignment use the following structs for Binary Trees and Binary Search Trees. struct Binode { int value; struct Bino

Question 2 [10 points] Write a function that gets a binary tree and returns the sum of its elements. // returns the sum of el

Functions and .h file:

1 #include <stdio.h> #include <stdlib.h> 5 #include assignment4.h 7 8 #ifndef ASSIGNMENT4 H #define ASSIGNMENT4 H 10 #inclu

Test function:

part 1:

9.bool BT_equal(BTnode_t* ti. BTnode_t* t2) { 18 if (tl == t2) 11 return true; 12 if ((t1 66!t2) || (!t1 && t2)) 13 return fa

part 2:

57 58 59 60 BST_t* create_my_BST() { BST_t* my_BST = create_BST(); BST_insert(my_BST, 5); BST_insert(my_BST, 6); BST_insert(m

0 0
Add a comment Improve this question Transcribed image text
Answer #1
int get_sum(BTnode_t *tree) {
    if (tree == NULL) {
        return 0;
    } else {
        return tree->value + get_sum(tree->left) + get_sum(tree->right);
    }
}

int get_min(BST_t *tree) {
    BTnode_t *temp = tree->root;
    while (temp->left != NULL) {
        temp = temp->left;
    }
    return temp->value;
}
Add a comment
Know the answer?
Add Answer to:
NEED HELP IN C!! Answer in C programming language. Question: Functions and .h file: Test function:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need to make it so this program outputs to an output.txt, the program works fine,...

    I need to make it so this program outputs to an output.txt, the program works fine, just need it to fprintf to output.txt #include <stdio.h> #include <string.h> #include <malloc.h> #define MAX 30 struct treeNode { char names[MAX];    struct treeNode *right; struct treeNode *left; }*node; void searchName(char names[], struct treeNode ** parent, struct treeNode ** location) { struct treeNode * ptr, * tempPtr; if(node == NULL)    { *location = NULL; *parent = NULL; return; } if(strcmp(names, node->names) == 0)...

  • BST.cpp #include "BST.h" #include "BT-visualize.h" #include <assert.h> #include <stdio....

    BST.cpp #include "BST.h" #include "BT-visualize.h" #include <assert.h> #include <stdio.h> #include <string.h> #include <string> // Implement the following five methods // inserts val into BST rooted at x and returns the tree's new root BTnode * insert(BTnode * x, int val) {} // returns true iff target in tree rooted at x bool search(BTnode * x, int target) {} // Find the maximum value of a tree rooted at x int findmax(BTnode * x) {} // Find the manimum value of...

  • Q1) Write a method called inToTree of ExpressionTree class which takes a string of infix expression...

    Q1) Write a method called inToTree of ExpressionTree class which takes a string of infix expression (fully parenthesized), resets the root of the expression tree to such tree which constructed from the expression. The root set to null of the expression contains characters other than value, operator, and parenthesis or if it’s not an in-fix full parenthesized expression. You may assume each value is single digit only . public void inToTree(String expression){ You may use a JCF Deque class as...

  • Coding Language: C++ Function Header: vector<vector<int>> printFromButtom(TreeNode* root) {} Definition for a binary tree node: struct...

    Coding Language: C++ Function Header: vector<vector<int>> printFromButtom(TreeNode* root) {} Definition for a binary tree node: struct TreeNode { int val; TreeNode *left; TreeNode *right; }; The Problem Complete the printFromButtom function that accepts a BST TreeNode and returns the nodes' value from left to right, level by level from leaf to root. This function will return vector<vector int which similar to a 2-D array. Function std: reverse (myvector.begin myVector en might be helpful. Definition for a binary tree node: struct...

  • Answer the following question(s) concerning implementing recursive functions to perform operations on linked lists of nodes...

    Answer the following question(s) concerning implementing recursive functions to perform operations on linked lists of nodes arranged as binary trees. For these questions, use the following struct definition for the nodes of the tree (we will not templatize the node here, so you do not have to write template functions for these questions, just assume trees of <int> values): struct BinaryTreeNode { int item; BinaryTreeNode* left; BinaryTreeNode* right; }; ---------------------------------------------- Given a node for a Binary Tree and an (integer)...

  • Add a non-recursive inorder() method to class LinkedBinaryTree<E> to traverse binary tree. Test inorder() method. Implementation...

    Add a non-recursive inorder() method to class LinkedBinaryTree<E> to traverse binary tree. Test inorder() method. Implementation in Java #########LinkedBinary Tree class######### public class LinkedBinaryTree<E> extends AbstractBinaryTree<E> { //---------------- nested Node class ---------------- /** Nested static class for a binary tree node. */ protected static class Node<E> implements Position<E> { private E element; // an element stored at this node private Node<E> parent; // a reference to the parent node (if any) private Node<E> left; // a reference to the left...

  • C++. Test if a Tree is Balanced Use the given Tree class and implement a function...

    C++. Test if a Tree is Balanced Use the given Tree class and implement a function to test if the binary tree is balanced or not. An empty tree is height-balanced. A non-empty binary tree T is balanced if: 1) Left subtree of T is balanced 2) Right subtree of T is balanced 3) The difference between heights of left subtree and right subtree is not more than 1. #include <iostream> using namespace std; template<class ItemType> class Tree { private:...

  • Having code issues wth my C++ program. My program checks if two binary trees are similar...

    Having code issues wth my C++ program. My program checks if two binary trees are similar and if they're not they return false. My program is return true with different binary trees. Could use some help thanks #include <iostream> #include <string> using namespace std; //Struct of Nodes struct BinarySearchTree { int data; BinarySearchTree *left; BinarySearchTree *right; }; // Inserting nodes into BST BinarySearchTree* insert( BinarySearchTree* node, int val) { if (node == NULL) { BinarySearchTree *newNode = new BinarySearchTree(); newNode->data...

  • C++. Test if a Tree is Balanced Use the given Tree class and implement a function...

    C++. Test if a Tree is Balanced Use the given Tree class and implement a function to test if the binary tree is balanced or not. An empty tree is height-balanced. A non-empty binary tree T is balanced if: 1) Left subtree of T is balanced 2) Right subtree of T is balanced 3) The difference between heights of left subtree and right subtree is not more than 1. Please MAKE SURE TO CLEARLY SHOW THE CODING. AND YOUR OUTPUT....

  • I am having problems with the following assignment. It is done in the c language. The...

    I am having problems with the following assignment. It is done in the c language. The code is not reading the a.txt file. The instructions are in the picture below and so is my code. It should read the a.txt file and print. The red car hit the blue car and name how many times those words appeared. Can i please get some help. Thank you. MY CODE: #include <stdio.h> #include <stdlib.h> #include <string.h> struct node { char *str; int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT