Segmentation Fault: gdb
<p>I am new to gdb and debugging in general, granted I am not sure how I have made it this far without gdb.  The program debugging that gdb tells me is that there is a segmentation fault in this function.  I will highlight it with a comment below:</p>

<pre><code>template &lt;class elemType&gt;
struct nodeType
{
    elemType info;
    nodeType&lt;elemType&gt; *lLink;
    nodeType&lt;elemType&gt; *rLink;
};

#define H_binarySearchTree
#include &lt;iostream&gt;
#include "binaryTree.h"

using namespace std;

template &lt;class elemType&gt;
class bSearchTreeType: public binaryTreeType&lt;elemType&gt;
{
public:
    bool search(const elemType&amp; searchItem) const;
    //Function to determine if searchItem is in the binary
    //search tree.
    //Postcondition: Returns true if searchItem is found in
    //               the binary search tree; otherwise,
    //               returns false.

    void insert(const elemType&amp; insertItem);
    //Function to insert insertItem in the binary search tree.
    //Postcondition: If there is no node in the binary search
    //               tree that has the same info as
    //               insertItem, a node with the info
    //               insertItem is created and inserted in the
    //               binary search tree.

    void deleteNode(const elemType&amp; deleteItem);
    //Function to delete deleteItem from the binary search tree
    //Postcondition: If a node with the same info as deleteItem
    //               is found, it is deleted from the binary
    //               search tree.
    //               If the binary tree is empty or deleteItem
    //               is not in the binary tree, an appropriate
    //               message is printed.
    void printTree();
    void printTree(nodeType&lt;elemType&gt; *p);
    // void printTreeNode(nodeType&lt;elemType&gt; *p);
    void swapSubtrees(nodeType&lt;elemType&gt; *root1);
    void swapSubtrees();
    nodeType&lt;elemType&gt; *root1;

    template &lt;class elemType&gt;
    void bSearchTreeType&lt;elemType&gt;::insert
    (const elemType&amp; insertItem)
    {
        nodeType&lt;elemType&gt; *current; //pointer to traverse the tree
        nodeType&lt;elemType&gt; *trailCurrent; //pointer behind current
        nodeType&lt;elemType&gt; *newNode;  //pointer to create the node

        newNode = new nodeType&lt;elemType&gt;;
        newNode-&gt;info = insertItem;
        newNode-&gt;lLink = NULL;
        newNode-&gt;rLink = NULL;

        if (root1 == NULL)
            root1 = newNode;
        else
        {
            current = root1;
            while (current != NULL)
            {
                trailCurrent = current;

                if (current-&gt;info == insertItem)//** This is where gdb says there is a seg fault
                {
                    cout &lt;&lt; "The item to be inserted is already ";
                    cout &lt;&lt; "in the tree -- duplicates are not "
                    &lt;&lt; "allowed." &lt;&lt; endl;
                    return;
                }
                else if (current-&gt;info &gt; insertItem)
                    current = current-&gt;lLink;
                else
                    current = current-&gt;rLink;
            }//end while

            if (trailCurrent-&gt;info &gt; insertItem)
                trailCurrent-&gt;lLink = newNode;
            else
                trailCurrent-&gt;rLink = newNode;
        }
    }//end insert

    template&lt;class elemType&gt;
    void bSearchTreeType&lt;elemType&gt;::swapSubtrees(nodeType&lt;elemType&gt; * root1)
    {

        if (root1 != NULL)
        {
            nodeType&lt;elemType&gt; *temp;

            swapSubtrees(root1-&gt;lLink);//Seg Fault here as well
            swapSubtrees(root1-&gt;rLink);

            temp =root1-&gt;lLink;

            root1-&gt;lLink = root1-&gt;rLink;
            root1-&gt;rLink = temp;
        }
    }
}
</code></pre>

<p>Could someone please help describe what is going on, and what I need to do to fix it?</p>

<p>*edited to include more details
Much Appreciated</p>
