Starting Out With C++: Early Objects (10th Edition)
Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 19, Problem 1PC
Program Plan Intro

Simple Binary Search Tree Class

Program Plan:

  • Include the required header files.
  • Define the class BTreeNode.
    • Create constructor by passing the three parameters.
    • Declare the object for binary tree.
    • Declare class BST has friend.
  • Define the class BST.
    • Define the search() function.
      • Call search() function recursively and then return the result.
    • Declare insert() function prototype.
    • Define inorder() function.
      • Call inorder() function recursively and then return the result.
    • Declare the private search() function prototype.
    • Declare the private inorder() function prototype.
  • In the search() function,
    • Check whether the tree is empty. If yes, return false, there is no node in tree.
    • Check whether the tree is equal to x. If yes, return true, the search value is found
    • Check whether the tree is greater than x. If yes, call search() function by passing left node and result is returned.
    • Otherwise, call search() function by passing right node and result is returned.
  • In the insert() function,
    • Check whether the tree is empty. If yes, create an object for binary tree.
    • Loop executes until the tree is not empty. If yes,
      • Check whether x is less than or equal to tree. If yes, x goes to left node of binary tree.
      • Otherwise, x goes to right node of binary tree.
  • In the inorder() function,
    • Check whether the tree is empty. If yes, exit the statement.
    • Call inorder() function by passing left node.
    • List the inorder elements from tree.
    • Call inorder() function by passing right node.
  • Define the “main()” function.
    • Read the five inputs from user.
    • Call insert() function to insert all elements into binary tree.
    • Call inorder() function to inorder the elements present in binary tree.
    • Call search() function to search the specified values and then displays it.

Blurred answer
Students have asked these similar questions
Course: Data Structure and Algorithms Language: C++ Question is well explained   Question #2Implement a class for Circular Doubly Linked List (with a dummy header node) which stores integers in unsorted order. Your class definitions should look like as shown below: class CDLinkedList;class DNode {friend class CDLinkedList;private int data;private DNode next;private DNode prev;};class CDLinkedList   {private:DNode head;                          // Dummy header nodepublic CDLinkedList();            // Default constructorpublic bool insert (int val);       public bool removeSecondLastValue ();                    public void findMiddleValue();                  public void display();                       };
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 64
Array_based circular queue: Define the class Queue using one dimensional circular array representation with no implementation; i.e. declare the data members, and the function members only (Enqueue, Dequeue, IsEmpty, GetHead etc.).                       Implement the Ennqueue method of the above class
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning