मैं वर्तमान में एक द्विआधारी पेड़ प्रत्यावर्तन का उपयोग करते हुए एक नोड डालने कठिनाई आ रही है। मैं इस समस्या पर कुछ दिनों के लिए अब में रहने वाली किया गया है और सोचा था कि यह समय मैं जवाब की तलाश में आया था!
नोड वर्ग (ज):
#ifndef STUDENT_MACROGUARD
#define STUDENT_MACROGUARD
#include <cstdlib>
#include <string>
namespace student_class
{
class student
{
public:
// Constructors / Destructors;
student(const float entry = 0, std::string name = ,
student* left_ptr = NULL, student* right_ptr = NULL);
~student(void){};
// Mutating member functions;
void set_grade(const float entry);
void set_name(std::string entry);
void set_left(student* node_ptr);
void set_right(student* node_ptr);
// Non mutating member functions;
float grade(void);
std::string name(void);
student* left(void);
student* right(void);
// Const member functions;
const student* left(void) const;
const student* right(void) const;
private:
std::string student_name;
float grade_field;
student* left_ptr;
student* right_ptr;
};
}
#endif
BSTree वर्ग बाइनरी ट्री डेटा संरचना (ज) को लागू करने:
#ifndef BTTree_MACROGUARD
#define BTTree_MACROGUARD
#include <cstdlib>
#include <string>
#include <iostream>
#include student.h
using namespace student_class;
namespace BTTree_class
{
class BTTree
{
public:
// Constructors / Destructors;
BTTree(student* node_ptr = NULL);
~BTTree(void);
// Mutating member functions;
void insert(student* node_ptr = NULL, const float grade = 0, std::string name = );
void remove(student* node_ptr);
// Non mutating member functions;
student* grade_search(const float entry);
student* name_search(const std::string entry);
student* root(void);
void print_tree(student* node_ptr);
// Const member functions;
const student* grade_search(const float entry) const;
const student* name_search(const float entry) const;
const student* root(void) const;
private:
student* root_ptr;
};
}
#endif
डालने सदस्य समारोह कार्यान्वयन मैं पेड़ में नोड्स सम्मिलित करने के लिए उपयोग कर रहा हूँ:
void BTTree::insert(student* node_ptr, const float grade, std::string name)
{
if(root_ptr == NULL)
{
root_ptr = new student(grade, name);
return;
}
if(node_ptr == NULL)
{
node_ptr = new student(grade, name);
return;
}
else if(node_ptr->grade() > grade)
{
insert(node_ptr->left(), grade, name);
}
else
{
insert(node_ptr->right(), grade, name);
}
}
मुझे समझ नहीं आता क्यों इस प्रविष्टि काम नहीं कर रहा है। कोड निर्दोष लग रहा है और यह मुझे बचा है मेरे सिर खरोंच। मैं एक वैकल्पिक प्रविष्टि समारोह जो यात्रा का उपयोग करता है लिखा है, लेकिन प्रत्यावर्तन बहुत जरूरी है।
किसी भी मदद शानदार होगा, धन्यवाद।













