For this assignment we are suppose to a public function to call a private function to do recursion.
As of now I'm not sure were to declare.
Depending on where I place it generates different errors. If i place it with Private functions the publics tell me its unidentified. Could i do a friend or something perhaps?Code:node *root;
its also telling me when i try to call my private functions from inside the public ones that.
example:
Insert takes 1 argument.
any assistant is appreciated.
Code:#include <string> using namespace std; class exception { public: void NonExistent() throw(); }; struct node { string data; node *left; node *right; }; class BSTree { public: void Insert(string); void InOrderTraversal(); void PreOrderTraversal(); void PostOrderTraversal(); int Count(); string First(); string Last(); private: void InOrderTraversal(node *current); void PreOrderTraversal(node *current); void PostOrderTraversal(node *current); int Count(node *current); string First(node *current); string Last(node *current); }; void Insert(string data) { root = new node; root->data = data; root->left = NULL; root->right = NULL; } //In order public and private functions void InOrderTraversal() { if (root == NULL) { return; } else { InOrderTraversal(); } } void InOrderTraversal(node *current) { if (current == NULL) { return; } else { InOrderTraversal(current->left); cout << current->data; InOrderTraversal(current->right); } } //Post order public and private functions void PostOrderTraversal() { if (root == NULL) { return; } else { PostOrderTraversal(root); } } void PostOrderTraversal(node *current) { if (current == NULL) { return; } else { PostOrderTraversal(current->left); PostOrderTraversal(current->right); cout << current->data; } } //Pre order public and private functions void PreOrderTraversal() { if (root == NULL) { return; } else { PreOrderTraversal(root); } } void PreOrderTraversal(node *current) { if (current == NULL) { return; } else { cout << current->data; PreOrderTraversal(current->left); PreOrderTraversal(current->right); } } int Count() { if (root == NULL) { return 0; } else { Count(root); } } int Count(node *current) { if (current == NULL) { return 0; } else { int count = 1; count += Count(current->left); count += Count(current->right); return count; } }



LinkBack URL
About LinkBacks


