Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,493 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,689 people online right now. Registration is fast and FREE... Join Now!




binary tree compilation errors

 
Reply to this topicStart new topic

binary tree compilation errors

kirby20
4 Mar, 2008 - 04:54 PM
Post #1

New D.I.C Head
*

Joined: 28 Feb, 2008
Posts: 2

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
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Binary Tree Compilation Errors
4 Mar, 2008 - 09:29 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,213



Thanked: 216 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
You have a lot of issues with this code. You use variables that are not defined, you have different names for the same function (you are saying there is a function called treeSearch, but then define mSearch, but use binsearch which is not even defined). Same with your insert (treeInsert, mInsert, and selection). On top of that these three functions don't even take the same number or type of parameters as passed to them. It is almost like you cut and paste this from various programs.

You also use tref data type in your definition of node, but you have not defined a tref type.

I suggest you either start from scratch and make sure the functions jive with one another or at least try and fix the inconsistencies.

Good luck.
User is online!Profile CardPM
+Quote Post

kirby20
RE: Binary Tree Compilation Errors
5 Mar, 2008 - 11:20 AM
Post #3

New D.I.C Head
*

Joined: 28 Feb, 2008
Posts: 2

I did not copy and paste. Good try! I am a beginner so I'm not sure if my declarations are correct and how my calls are correct, espcially in mInsert().
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 07:54PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month