Question

Use a B-Tree to implement the set.h class. #ifndef MAIN_SAVITCH_SET_H #define MAIN_SAVITCH_SET_H #include <cstdlib> // Provides...

Use a B-Tree to implement the set.h class.

#ifndef MAIN_SAVITCH_SET_H
#define MAIN_SAVITCH_SET_H
#include <cstdlib> // Provides size_t

namespace main_savitch_11
{
template <class Item>
class set
{
public:
// TYPEDEFS
typedef Item value_type;
// CONSTRUCTORS and DESTRUCTOR
set( );
set(const set& source);
~set( ) { clear( ); }
// MODIFICATION MEMBER FUNCTIONS
void operator =(const set& source);
void clear( );
bool insert(const Item& entry);
std::size_t erase(const Item& target);
// CONSTANT MEMBER FUNCTIONS
std::size_t count(const Item& target) const;
bool empty( ) const { return (data_count == 0); }
// SUGGESTED FUNCTION FOR DEBUGGING
void print(int indent) const;
private:
// MEMBER CONSTANTS
static const std::size_t MINIMUM = 200;
static const std::size_t MAXIMUM = 2 * MINIMUM;
// MEMBER VARIABLES
std::size_t data_count;
Item data[MAXIMUM+1];
std::size_t child_count;
set *subset[MAXIMUM+2];
// HELPER MEMBER FUNCTIONS
bool is_leaf( ) const { return (child_count == 0); }
bool loose_insert(const Item& entry);
bool loose_erase(const Item& target);
void remove_biggest(Item& removed_entry);
void fix_excess(std::size_t i);
void fix_shortage(std::size_t i);
// NOTE: The implementor may want to have additional helper functions
};
}
#include "set.template" // Include the implementation.

#endif

We have to code all the public functions. I don't know how to go about this. Can you help me code this? Don't we need a root_ptr?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Let consider B-tree are alternative to indexed-sequential files. B-tree is a self-balancing tree data structure that maintains sorted data and allows searches, sequential access, insertions, and deletions in logarithmic time. The B-tree generalizes the binary search tree, allowing for nodes with more than two children.

Let we considered the below code has to be discussed.

#ifdef is preprocessor directive in programing languages.

#endif - is must be closed the directive.

#define, #include.... are header file in programing code.

namespaces -

as you've done - is to avoid putting things in the global namespace so they won't be accidentally picked up by other code or the linker.

Public: -

public function, which means the function is visible from outside the class.

typedefs-  

keyword is used to assign a new name to a type. This is used just to prevent us from writing more. For example, if we want to declare some variables of type unsigned int , we have to write unsigned int in a program and it can be quite hectic for some of us.

Constructer and destructor are-set( );
set(const set& source);
~set( ) { clear( ); }//Constructors are special class functions which performs initialization of every object. The Compiler calls the Constructor whenever an object is created. ... Whereas, Destructor on the other hand is used to destroy the class object.

Modification member fuction-

A modifier, also called a modifying function, is a member function that changes the value of at least one data member. In other words, an operation that modifies the state of an object. Modifiers are also known as 'mutators'.

Constant member function -

A constant (const) member function can be declared by using const keyword, it is used when we want a function that should not be used to change the value of the data members i.e. any type of modification is not allowed with the constant member function

MEMBER CONSTANTS
static const std::size_t MINIMUM = 200;// 200 is a constant value for size_t
static const std::size_t MAXIMUM = 2 * MINIMUM// 2*MINIMUM are constant value maximum size_t.

MEMBER VARIABLES
std::size_t data_count;
Item data[MAXIMUM+1];
std::size_t child_count;
set *subset[MAXIMUM+2]; // here declared member variable data _count, child_count are the member variable assigned with data type.

HELPER MEMBER FUNCTIONS-

A helper function is a function (usually supplied by the writer of a class) that does not need direct access to the representation of the class, yet is seen as part of the useful interface to the class.

#endif-

-is must be closed the directive.

Here the code to specify the B-tree node insertion deletion process.

Root_ptr condition dont we needed.

B-tree of oreder M is an M way tree (m-ary).

The root is either a leaf node or M children. So can't use root_ptr.

Add a comment
Know the answer?
Add Answer to:
Use a B-Tree to implement the set.h class. #ifndef MAIN_SAVITCH_SET_H #define MAIN_SAVITCH_SET_H #include <cstdlib> // Provides...
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
  • Was converting the main into a template but I am recieving errors, what should I be...

    Was converting the main into a template but I am recieving errors, what should I be doing? #include<iostream> #include <cstdlib> #include "set.h" using namespace std; int main() {    set<Item> list;    list.insert(4);    list.insert(7);    list.insert(9);    list.insert(3); cout<< "The list contains "<<list.contains(4)<<" number of fours"<<endl;    list.erase(4); cout<< "The list contains "<<list.contains(4)<<" number of fours"<<endl; } #ifndef SET_H #define SET_H #include<cstdlib> namespace std {    template<class Item> class set_item { public: typedef Item value_type; set_item( ) { next...

  • c++ Sequence class is a class that supports sequence of integers. Run the project ad verify...

    c++ Sequence class is a class that supports sequence of integers. Run the project ad verify that project works for integers. Next convert your sequence class into a template class. Demonstrate in your main function by using a sequence of int, float, string. sequence.cxx #include // Provides assert using namespace std; namespace main_savitch_3 { sequence::sequence() { used = 0; current_index = 0; } void sequence::start() { current_index = 0; } void sequence::advance() // Library facilities used: assert.h { assert(is_item()); current_index++;...

  • The purpose of this program is to help reinforce container class concepts and linked list concepts...

    The purpose of this program is to help reinforce container class concepts and linked list concepts in C++. Specifically, the task is to implement the sequence class using a linked list. You need to use the author's file sequence3.h to create your implementation file named sequence3.cpp. Please make your code as efficient and reusable as possible. Please make sure code can pass any tests. sequence3.h // FILE: sequence3.h // CLASS PROVIDED: sequence (part of the namespace main_savitch_5) // This is...

  • The purpose of this lab is to help reinforce container class concepts and linked list concepts...

    The purpose of this lab is to help reinforce container class concepts and linked list concepts in C++. Specifically, the lab to repeat the sequence lab from last week except to use a linked list. You need to use the author's files sequence3.h and sequence_exam3.cpp. Author - Michael Main, Book - Data Structures and other objects using c++, 4th edition // FILE: sequence3.h // CLASS PROVIDED: sequence (part of the namespace main_savitch_5) // This is the header file for the...

  • The goal of this task is to reinforce the implementation of container class concepts using linked...

    The goal of this task is to reinforce the implementation of container class concepts using linked lists. Specifically, the task is to create an implementation file using a linked list. You need to use the header files, set3.h and node1.h, and the test program, test_set3.cpp. Your documentation must include the efficiency of each function. Please make your program as efficient and reusable as possible. set3.h #ifndef _SET_H #define _SET_H #include <cstdlib> #include <iostream> class set { public: typedef int value_type;...

  • Please Help This: please follow style guidelines Rule 1: use const where appropriate Rule 2: every...

    Please Help This: please follow style guidelines Rule 1: use const where appropriate Rule 2: every member function must include a description in the header file including precondition and postcondition. Rule 3: every member variable must include a description of what the variable holds. Rule 4: Classes should be capitalized. Bag, not bag. Person, not person. (I know this is different than how the book does it) Rule 5: member variables of classes should be preceded by “m_”. If it’s...

  • #ifndef HEAP_H_ #define HEAP_H_ namespace cse { template<typename dtype> class heap { public: /** TO DO::...

    #ifndef HEAP_H_ #define HEAP_H_ namespace cse { template<typename dtype> class heap { public: /** TO DO:: default constructor perform new to reserve memory of size INITIAL_CAPACITY. set num_items = 0; */ heap() { // write your code here }; /** Create a heap from a given array */ heap(dtype *other, size_t len) { // write your code here }; /** copy constructor copy another heap to this heap. */ heap(const heap<dtype> &other) { //write your code here }; /** Accessor...

  • The goal is to reinforce the implementation of container class concepts in C++. Specifically, the goal...

    The goal is to reinforce the implementation of container class concepts in C++. Specifically, the goal is to create a static implementation of a set. Add the efficiency of each function to the documentation in the header file. Your program must compile. Use test_set.cpp as your test program. Set.h & Test_Set.cpp is code that is already given. All I need is for you add comments to Set.cpp describing each function. FILE: SET.H #ifndef _SET_H #define _SET_H #include <cstdlib> #include <iostream>...

  • PLEASE HURRY. Below is the prompt for this problem. Use the code for bag1.cxx, bag1.h and...

    PLEASE HURRY. Below is the prompt for this problem. Use the code for bag1.cxx, bag1.h and my code for bag.cpp. Also I have provided errors from linux for bag.cpp. Please use that code and fix my errors please. Thank you The goal of assignment 3 is to reinforce implementation of container class concepts in C++. Specifically, the assignment is to do problem 3.5 on page 149 of the text. You need to implement the set operations union, intersection, and relative...

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
ADVERTISEMENT