summaryrefslogtreecommitdiffstats
path: root/Bachelor/Prog2/SortedList/Ref.cpp
blob: 49547a56c3c558c10ab5b768efc385b59a5a62a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
template< class NODETYPE >

void Tree< NODETYPE >::insertNode( const NODETYPE &value )

   { insertNodeHelper( rootPtr, value ); }



// This function receives a reference to a pointer so the

// pointer itself (not a copy of it!) can be modified.

template< class NODETYPE >

void Tree< NODETYPE >::insertNodeHelper( 

        TreeNode< NODETYPE >*& ptr, const NODETYPE &value )

{

   if ( ptr == 0 ) {                   // tree is empty

      ptr = new TreeNode< NODETYPE >( value );

      assert( ptr != 0 );

   }

   else                              // tree is not empty

      if ( value < ptr->data )

         insertNodeHelper( ptr->leftPtr, value );

      else

         if ( value > ptr->data )

            insertNodeHelper( ptr->rightPtr, value );

         else

            cout << value << " dup" << endl;

}