Ok, i'm trying to create a binary tree that reads in data from another file, but i'm having trouble with the compilation errors. one of the errors said something like "ambiguous call to overloaded function."
about my program: create a tree and insert the name of the months in order, while also placing the months in alphabetical order in the tree.
ex. of tree from jan to june:
CODE
[January]
/ \
[February] [March]
/ \ / \
[April] [June] [NULL] [May]
here is what i have. any help would be appreicated. thanks.
CODE
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
using namespace std;
typedef char monthName[25];
typedef struct node* treeRef;
typedef struct node
{
monthName mo;
tref left;
tref right;
} treeNode;
/*Searches a binary tree for a month*/
void mSearch(monthName month, treeRef root, bool& found, treeRef& curNode, treeRef& CurPrev);
/*Inserts a month into the tree
-If root is null, don't call search and just insert by creating a new node
-In the new node, null out the left and right pointers
-Starts with January repectively, and insert makes sure the tree is in alpha order*/
void mInsert(monthName month);
/*-reads in a file "month.dat" which contain all the months starting with Janurary and ends with December
-create an interface that searches for a month and/or inserts*/
int main()
{
monthName month;
bool found = false;
int cur;
int choice;
ifstream infile;
infile.open("month.dat");
infile >> month;
while(!infile.eof())
{
insertion(keyname);
infile >> keyname;
}
infile.close();
for(int i = 0; i <=100; i++)
{
cout << "Make a Selection" << endl;
cout << "1) Search tree for a month" << endl;
cout << "2) Insert a month into tree" << endl;
cout << "3) Exit" << endl;
cin >> selection;
if(selection == 1)
cin >> monthname;
binsearch(monthname, found, cur);
if(selection == 2)
insertion(monthname);
if(selection == 3)
exit(1);
}
}
void mSearch(monthName month, treeRef root, bool& found, treeRef& curNode, treeRef& CurPrev)
{
treeRef r = root;
treeRef rPrev = NULL;
while(p != NULL && strcmp(p->mo, month) != 0)
{
rPrev = r;
if(strcmp(r->mo, month) > 0)
r = r->left;
else
r = r->right;
}
found = (r != NULL);
curNode = r;
CurPrev = rPrev;
}
void mInsert(monthName month)
{
treeRef root = NULL;
bool found = true;
treeRef curNode;
treeRef CurPrev;
while(root != NULL)
{
mSearch(keyname, root, found, curNode, CurPrev);
if(month != found)
cin >> month;
}
else
{
root = new treeNode;
root->left = NULL;
root->right = NULL;
}
}
This post has been edited by kirby20: 5 Mar, 2008 - 11:15 AM