Insert Book Structure Into Binary Tree C++
<p>I have a book structure that contains a book title, url, and student name. I want to insert this data into a binary tree. I have already coded these functions but am not able to get an output when trying to print the tree.</p>

<p>1) Does my insert function look correct?</p>

<p>2) Does my printTree function look correct?</p>

<p>3) When I call on the printTree function I am passing pointer. If I want to just print from the root down what do I pass as the root? </p>

<p>Relevant code is as follows:</p>

<pre><code>typedef struct book {
    char title[75];
    char url[75];
    char student[50];
} BOOK;

struct tree_node {
    BOOK data;
    struct tree_node *left;
    struct tree_node *right;
};


    int insert_book() {     // insert an new book

        BOOK contact;

        cout &lt;&lt; endl &lt;&lt; "@Inserting Book.........." &lt;&lt; endl;
        cout &lt;&lt; "Enter the Book Title: ";
        cin.ignore();
        cin.getline(contact.title, 75);
        cout &lt;&lt; "Enter the Book URL: ";
        cin.getline(contact.url, 75);
        cout &lt;&lt; "Enter the Student: ";
        cin.getline(contact.student, 50);


        void insert(BOOK, tree_node); 

        return 0;

    }


    struct tree_node * insert(BOOK contact, struct tree_node* node) {

        if(node == NULL)
            return(create_node(contact));

        else if(strcmp(contact.student, node-&gt;data.student) &lt;= 0)
            node-&gt;left = insert(contact, node-&gt;left);

        else if(strcmp(contact.student, node-&gt;data.student) &gt;= 0)
            node-&gt;right = insert(contact, node-&gt;right);

        return (node);
    }

    struct tree_node* create_node(BOOK contact) {

        struct tree_node* node = new(struct tree_node);

        node-&gt;data = contact;
        node-&gt;left = NULL;
        node-&gt;right = NULL;

        return(node);
    } 

    void printTree(struct tree_node* node) { 
        if (node == NULL)
            cout &lt;&lt; "Empty!" &lt;&lt; endl;
        if(node != NULL) {
            printTree(node-&gt;left); 
            printf("%d ", node-&gt;data); 
            printTree(node-&gt;right);
        }
    }
</code></pre>
