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
  • C++ I need help adding to this program. Here's my assignment: (1) Add the following functions...

    C++ I need help adding to this program. Here's my assignment: (1) Add the following functions to your working mixed number class: Overload the ==, <, and > comparison operators Overload the + and * arithmetic operators Overload the insertion (<<) operator: It should display whole part, space, numerator, forward slash, denominator: 5 4/13 Overload the extraction (>>) operator: It should read integer, integer, character, integer. That is, it can assume that the numerator, forward slash, and denominator are input...

  • 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)...

  • Language: C++ ○ For this question I task you with creating an Iterative Search function that...

    Language: C++ ○ For this question I task you with creating an Iterative Search function that works with the existing binary search tree of type string. This function will be inputted a variable of type string and will search for it within the existing and pre-declared binary tree. ○ The function appears just above the main, and is simply a placeholder. It can be altered as you wish. ○ Within the Main I have a simple program to prompt for...

  • 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...

  • 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...

  • C++ Data Structures and Algorithms Binary Trees: Implementation Answer the following question(s) concerning implementing recursive functions...

    C++ Data Structures and Algorithms Binary Trees: Implementation 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; }; Write a recursive function...

  • 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)...

  • 1. the path length of a binary tree BT is the sum of the depths of...

    1. the path length of a binary tree BT is the sum of the depths of all position in BT. write and test a linear-time java method for computing the path length of a binary tree BT. add the method to linkedbinarytree class and write testing code in main method. hint: add method to linkedbinarytree class and write testing in main method public class LinkedBinaryTree<E> extends AbstractBinaryTree<E> { //---------------- nested Node class ---------------- /** Nested static class for a binary...

  • 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...

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