i need algorithm for r tree in c and along with c code with
i need algorithm for r- tree in c++ and along with c++ code with setp by step explanation of code
Solution
#include <iostream>
 #include \"RTree.h\"
using namespace std;
typedef int vluType;
struct Rctt
 {
 Rctt() {}
Rctt(int AMIN, int aMINy, int aMINX, int AMXVY)
 {
 min[0] = AMIN;
 min[1] = aMINy;
max[0] = aMINX;
 max[1] = AMXVY;
 }
 int min[2];
 int max[2];
 };
struct Rctt rcgcs[] =
 {
 Rctt(0, 0, 2, 2),
 Rctt(5, 5, 7, 7),
 Rctt(8, 5, 9, 6),
 Rctt(7, 1, 9, 2),
 };
int nrects = sizeof(rcgcs) / sizeof(rcgcs[0]);
Rctt search_rect(6, 4, 10, 6); // search will find above rcgcs that this one overlaps
 bool mysrchCallbak(vluType id, void* arg)
 {
 cout << \"Hit data rect \" << id << \"\ \";
 return true;
 }
 int main()
 {
 typedef RTree<vluType, int, 2, float> MyTree;
 MyTree tree;
int i, nhits;
 cout << \"nrects = \" << nrects << \"\ \";
for(i=0; i<nrects; i++)
 {
 tree.Insert(rcgcs[i].min, rcgcs[i].max, i); // Note, all values including zero are fine in this version
 }
nhits = tree.Search(search_rect.min, search_rect.max, mysrchCallbak, NULL);
cout << \"Search resulted in \" << nhits << \" hits\ \";
  
 int itIndex = 0;
 MyTree::Iterator it;
 for( tree.GetFirst(it);
 !tree.IsNull(it);
 tree.GetNext(it) )
 {
 int value = tree.GetAt(it);
int boundsMin[2] = {0,0};
 int boundsMax[2] = {0,0};
 it.GetBounds(boundsMin, boundsMax);
 cout << \"it[\" << itIndex++ << \"] \" << value << \" = (\" << boundsMin[0] << \",\" << boundsMin[1] << \",\" << boundsMax[0] << \",\" << boundsMax[1] << \")\ \";
 }
// Iterator test, alternate syntax
 itIndex = 0;
 tree.GetFirst(it);
 while( !it.IsNull() )
 {
 int value = *it;
 ++it;
 cout << \"it[\" << itIndex++ << \"] \" << value << \"\ \";
 }
return 0;
 }


