Good morning everyone...
I'm hoping someone can see what it is I'm doing wrong here -- basically the code complies however I get a run time error and I'm no sure why....
help, please...
CODE
/////// ********* GeneralTree.h *********///////
///////-------------------------------------///////
#ifndef GENERALTREE_h
#define GENERALTREE_h
#include <iostream>
using namespace std;
class GeneralTree{
public:
struct GenTreeNode{
int int_transactionID, int_totalNumChildren;
GenTreeNode *ptr_nextChild;
};
//initialize root
GenTreeNode *root;
GeneralTree(){
int int_totalNumChildren = 0;
}
~GeneralTree(){
clear();
}
void clear(){
//point to the node to be deleted
GenTreeNode *tmp;
//used to visit each node in the tree.
//We start with the first actual node off of "root"
GenTreeNode *traverse = root->ptr_nextChild;
//while the tree is not empty
while(traverse != NULL){
//store the current node
tmp = traverse;
//visit the next node
traverse = traverse->ptr_nextChild;
//free the memory taken up by the current node
delete tmp;
}
}
void addChildren(int *tranID, int cNo){
int int_totalNumChildren = cNo;
GenTreeNode *genTree = new GenTreeNode[int_totalNumChildren];
for(int i=0; i<int_totalNumChildren; i++){
genTree->int_transactionID = tranID[i];
}
}
void PrintTree(GenTreeNode *tree) {
/* .: Print all the items in the tree to which root points...the item in the root is printed first, followed by its children :: as long as the root is not empty :. */
if (tree != NULL){
cout << tree->int_transactionID << " ::- " << tree->int_totalNumChildren << endl;
// Print children
PrintTree(tree->ptr_nextChild);
}
}
void deleteChild(GenTreeNode *ChildPtr){
}
};
#endif
CODE
/////// ********* Main.cpp *********///////
///////-------------------------------///////
#include <iostream>
#include <fstream>
#include "GeneralTree.h"
using namespace std;
int main(){
GeneralTree *gTree = new GeneralTree;
int tID = 100;
int numOfChildren = 10;
cfisTree->addChildren(&tID, numOfChildren);
cfisTree->PrintTree(gTree->root);
return 0;
}