Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use c++ to create the following methods. Constructor, Copy Constructor, O verloa

ID: 3601325 • Letter: U

Question

Use c++ to create the following methods. Constructor, Copy Constructor, Overloaded assignment operator, Destructor, insert, retrieve, getHeight, getCount, clear, isEmpty, showStructure for this binary search tree ADT. Please use recursions and make sure to add all the helper functions. Thanks

template < typename DataType, class KeyType > // DataType : tree data item

class BSTree // KeyType : key field

{

public:

// Constructor

BSTree (); // Default constructor

BSTree ( const BSTree<DataType,KeyType>& other ); // Copy constructor

BSTree& operator= ( const BSTree<DataType,KeyType>& other );

                          // Overloaded assignment operator

// Destructor

~BSTree ();

// Binary search tree manipulation operations

void insert ( const DataType& newDataItem ); // Insert data item

bool retrieve ( const KeyType& searchKey, DataType& searchDataItem ) const;

// Retrieve data item

bool remove ( const KeyType& deleteKey ); // Remove data item

void writeKeys () const; // Output keys

void clear (); // Clear tree

// Binary search tree status operations

bool isEmpty () const; // Tree is empty

// !! isFull() has been retired. Not very useful in a linked structure.

// Output the tree structure -- used in testing/debugging

void showStructure () const;

/*

int getHeight () const; // Height of tree

int getCount () const;              // Number of nodes in tree

void writeLessThan ( const KeyType& searchKey ) const; // Output keys < searchKey

*/

protected:

class BSTreeNode // Inner class: facilitator for the BSTree class

{

public:

  

// Constructor

BSTreeNode ( const DataType &nodeDataItem, BSTreeNode *leftPtr, BSTreeNode *rightPtr );

// Data members

DataType dataItem; // Binary search tree data item

BSTreeNode *left, // Pointer to the left child

   *right; // Pointer to the right child

};

// Recursive helpers for the public member functions -- insert

// prototypes of these functions here.

void showHelper ( BSTreeNode *p, int level ) const;

// Data member

BSTreeNode *root; // Pointer to the root node

};

using namespace std; template / DataType tree data item class BSTree // KeyType: key field public: // Constructor BSTree O BSTree const BSTree& other 1/ Copy constructor BSTree& operator= ( const BSTree«DataType, KeyType>& other ); // Default constructor // Overloaded assignment operator // Destructor BSTree ) // Binary search tree manipulation operations void insert const DataType& newDataItem; II Insert data item bool retrieve const KeyType&searchKey;, DataType& searchDataltem const;

Explanation / Answer

#include int main() { int num; FILE *fptr; fptr = fopen("C:\program.txt","w"); if(fptr == NULL) { printf("Error!"); exit(1); } printf("Enter num: "); scanf("%d",&num); fprintf(fptr,"%d",num); fclose(fptr); return 0; }