Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 19, Problem 2RQE
Program Description Answer
A binary tree contains left and right pointers points to the “root” node.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
#ifndef BT_NODE_H#define BT_NODE_H
struct btNode{ int data; btNode* left; btNode* right;};
// pre: bst_root is root pointer of a binary search tree (may be 0 for// empty tree) and portArray has the base address of an array large// enough to hold all the data items in the binary search tree// post: The binary search tree has been traversed in-order and the data// values are written (as they are encountered) to portArray in// increasing positional order starting from the first elementvoid portToArrayInOrder(btNode* bst_root, int* portArray);void portToArrayInOrderAux(btNode* bst_root, int* portArray, int& portIndex);
// pre: (none)// post: dynamic memory of all the nodes of the tree rooted at root has been// freed up (returned back to heap/freestore) and the tree is now empty// (root pointer contains the null address)void tree_clear(btNode*& root);
// pre: (none)// post: # of nodes contained in tree rooted at root is returnedint…
Find the errors in the program then correct them.
CODE:
#include <bits/stdc++.h>using namespace std; /* A binary tree node has key, pointer to leftchild and a pointer to right child */struct Node { int key; struct Node *left, *right}; /* function to create a new node of tree andreturn pointer */struct Node* newNode(int key){ struct Node* temp = new node; temp->key = key; temp->left = temp->right = NULL; return temp;}; /* Inorder traversal of a binary tree*/void inorder(struct Node* temp){ if (!temp) return 0 inorder(temp->left); cout << temp->key << " "; inorder(temp->right)} /* function to delete the given deepest node(d_node) in binary tree */void deletDeepest(struct Node* root, struct Node* d_node){ queue<struct Node*> q q.push(root); // Do level order traversal until last node struct Node* temp; while (!q.empty()) { temp = q.front(); q.pop(); if (temp…
C programming I need help writing a code that uses a struct pointer into a binary tree and using the same pointer into an array
Chapter 19 Solutions
Starting Out With C++: Early Objects (10th Edition)
Ch. 19.1 - Prob. 19.1CPCh. 19.1 - Prob. 19.2CPCh. 19.1 - Prob. 19.3CPCh. 19.1 - Prob. 19.4CPCh. 19.1 - Prob. 19.5CPCh. 19.1 - Prob. 19.6CPCh. 19.2 - Prob. 19.7CPCh. 19.2 - Prob. 19.8CPCh. 19.2 - Prob. 19.9CPCh. 19.2 - Prob. 19.10CP
Ch. 19.2 - Prob. 19.11CPCh. 19.2 - Prob. 19.12CPCh. 19 - Prob. 1RQECh. 19 - Prob. 2RQECh. 19 - Prob. 3RQECh. 19 - Prob. 4RQECh. 19 - Prob. 5RQECh. 19 - Prob. 6RQECh. 19 - Prob. 7RQECh. 19 - Prob. 8RQECh. 19 - Prob. 9RQECh. 19 - Prob. 10RQECh. 19 - Prob. 11RQECh. 19 - Prob. 12RQECh. 19 - Prob. 13RQECh. 19 - Prob. 14RQECh. 19 - Prob. 15RQECh. 19 - Prob. 16RQECh. 19 - Prob. 17RQECh. 19 - Prob. 18RQECh. 19 - Prob. 19RQECh. 19 - Prob. 20RQECh. 19 - Prob. 1PCCh. 19 - Prob. 2PCCh. 19 - Prob. 3PCCh. 19 - Prob. 4PCCh. 19 - Prob. 5PCCh. 19 - Prob. 6PCCh. 19 - Prob. 7PCCh. 19 - Prob. 8PCCh. 19 - Prob. 9PCCh. 19 - Prob. 10PC
Knowledge Booster
Similar questions
- CO LL * Question Completion Status: QUESTION 3 Write a recursive function, OnlyChild(..), that returns the number of nodes in a binary tree that has only one child. Consider binaryTreeNode structure is defined as the following. struct binaryTreeNode int info; binaryTreeNode *llink: binaryTreeNode *rlink; The function is declared as the following. You must write the function as a recursive function. You will not get any credits if a non-recursive solution is used. int OnlyChild(binaryTreeNode *p); For the toolbar, press ALT+F10 (PC) or ALT+FN+F10 (Mac). Paragraph Arial 10pt B. ^三へ三 三山 三Ex? X2 = E E E 9 Click Save and Submit to save and submit. Click Save All Answers to save all ansuwers. Is E English (United States) Focus || 15 stv MacBook Air D00 O00 F4 F5 F8 64arrow_forwardA tree is implemented using a node structure defined as: struct node{ int data; struct node *left; strict node *right; }; Write a function whose prototype is: int smallest(struct node *); which accepts a tree (pointer to the root) and returns the smallest node in the right sub-tree of the root. If root is NULL, or if there is no right sub-tree, returm the number -999.arrow_forwardPythin: A binary search tree, write a function that finds and returns the median value. Assume that the class member variable. [_size] contains the number of elements in the binary search tree. What is the time complexity of your function? def find_median(self):arrow_forward
- Programming questions:typedef struct node { int data; struct node *left, *right;}BT;The node structure of the binary tree (BT) is shown above. There is a binary tree T, please complete the function: int degreeone(BT *T) to compute how many degree 1 node in the BT. The T is the root pointer, and the function shoule return the total number of degree 1 node.arrow_forwardQ5_3\ Represent the following tree by using array.arrow_forwardAssume the tree node structure is following........ struct node { int data; struct node* left; struct node* right; }; struct node *root = null; and there is a created new node function, called newnode(int new_data). Please filled the Blank of Insertion function. void insert(struct node *root, int key) { struct node *current; queue q; q.enque(root); while(!q.empty() } current = q.front(); q.deque(); if(current->left == NULL) { break; } else } q.enque( if(current->right == NULL) { break; else q.enque(_ = newnode(key); = newnode(key); _-));arrow_forward
- Computer Science lab3.h ------------- #include<stdio.h> #include<stdlib.h> #ifndef LAB3_H #define LAB3_H // A linked list node struct Node { int data; //Data struct Node *next; // Address to the next node }; //initialize: create an empty head node (whose "data" is intentionally missing); This head node will not be used to store any data; struct Node *init () { //create head node struct Node *head = (struct Node*)malloc(sizeof(struct Node)); } //Create a new node to store data and insert it to the end of current linked list; the head node will still be empty and data in the array in "main.c" are not stored in head node void insert(struct node *head, int data) { struct Node *newNode = (struct Node*)malloc(sizeof(struct Node)); new_node->data = data; new_node->next= head; } //print data for all nodes in the linked list except the head node (which is empty) void display (struct Node *head) { struct Node *current_node = head; while ( current_node != NULL) { printf("%d ",…arrow_forwardDouble pointers: Describe how this operation can be done in O(1) time if there are pointers in each node to both the previous and the next node.arrow_forwardFill-in-the-Blank In a(n) __________ list, each node has a pointer to the one before it and the one after it.arrow_forward
- C++ PROGRAMMINGTopic: Binary Search Trees Explain the c++ code below.: SEE ATTACHED PHOTO FOR THE PROBLEM INSTRUCTIONS It doesn't have to be long, as long as you explain what the important parts of the code do. (The code is already implemented and correct, only the explanation needed) node* left(node* p) { return p->left; } node* right(node* p) { return p->right; } node* sibling(node* p){ if(p != root){ node* P = p->parent; if(left(P) != NULL && right(P) != NULL){ if(left(P) == p){ return right(P); } return left(P); } } return NULL; } node* addRoot(int e) { if(size != 0){ cout<<"Error"<<endl; return NULL; } root = create_node(e,NULL); size++; return root; } node* addLeft(node* p, int e) {…arrow_forwardin c++, write a function to find the height of a specific node in a Binary Search Tree.arrow_forwardc++ code screenshot and output is mustarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning