Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

bool comp( const Write a function bool comp( const Search_tree x, const Search_tree y) to compare two binary search trees x, y, that store integer

bool comp(const Write a function

bool comp( const Search_tree x, const Search_tree y)

to compare two binary search trees x, y, that store integer data. If the two trees contain the same set of integers, the function should return true, and false otherwise. Note that two binary search trees could have different topological structure but still contain the same data. You have to write all the methods and functions you need (e.g., if you use a traversal method, you have to write it here). Your function should be computationally efficient.

template <class Record>

class Search_tree: public Binary_tree {

public:

private: // Add auxiliary function prototypes here.

Search_tree x, const Search_tree y) // WRITE THIS FUNCTION

A binary search tree is implemented using the following node and class structure. Write a method void rank(int k, Entry &x) that returns the k-th ranked entry in x (assume 1<=k<=n where n is the number of items in the binary search tree.) Your method should stop the search as soon as the k-th item is found.

template <class Entry>

struct Binary_node {

// data members:

Entry data;

Binary_node *left;

Binary_node *right;

// constructors:

Binary_node( );

Binary_node(const Entry &x);

};

template <class Entry>

class Binary_tree {

public:

Binary_tree( );

bool rank(int k, Entry &x); // returns the k-th ranked entry in x

protected:

// Add auxiliary function prototypes here.

Binary_node *root;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Online Market Research Cost Effective Searching Of The Internet And Online Databases

Authors: John F. Lescher

1st Edition

0201489295, 978-0201489293

More Books

Students also viewed these Databases questions

Question

3. Is it a topic that your audience will find worthwhile?

Answered: 1 week ago

Question

Understand why customers are loyal to a particular service firm.

Answered: 1 week ago