diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Bachelor/Prog2/SortedList/Ref.cpp | |
| download | Studium-master.tar.gz Studium-master.tar.bz2 | |
Diffstat (limited to 'Bachelor/Prog2/SortedList/Ref.cpp')
| -rw-r--r-- | Bachelor/Prog2/SortedList/Ref.cpp | 23 |
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 |
