summaryrefslogtreecommitdiffstats
path: root/Bachelor/Prog2/SortedList/Ref.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Bachelor/Prog2/SortedList/Ref.cpp')
-rw-r--r--Bachelor/Prog2/SortedList/Ref.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/Bachelor/Prog2/SortedList/Ref.cpp b/Bachelor/Prog2/SortedList/Ref.cpp
new file mode 100644
index 0000000..49547a5
--- /dev/null
+++ b/Bachelor/Prog2/SortedList/Ref.cpp
@@ -0,0 +1,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;
+} \ No newline at end of file