summaryrefslogtreecommitdiffstats
path: root/Bachelor/Prog2/SortedList/Ref.cpp
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Bachelor/Prog2/SortedList/Ref.cpp
downloadStudium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.gz
Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.bz2
add new repoHEADmaster
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