summaryrefslogtreecommitdiffstats
path: root/Bachelor/Prog2/SortedList2/SL_test.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/SortedList2/SL_test.cpp
downloadStudium-master.tar.gz
Studium-master.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Bachelor/Prog2/SortedList2/SL_test.cpp')
-rw-r--r--Bachelor/Prog2/SortedList2/SL_test.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/Bachelor/Prog2/SortedList2/SL_test.cpp b/Bachelor/Prog2/SortedList2/SL_test.cpp
new file mode 100644
index 0000000..f836972
--- /dev/null
+++ b/Bachelor/Prog2/SortedList2/SL_test.cpp
@@ -0,0 +1,75 @@
+// Driver for SortedList
+// Author: U.Breymann / H.P.Weber
+// Date: 05.05.05
+
+#include <iostream>
+using std::cout;
+using std::endl;
+
+#include <iomanip>
+using std::setw;
+
+#include <algorithm> // std::copy
+
+#include <cmath> // sin()
+#include <cstdlib> // abs(int)
+
+#include "SortedList.h"
+
+template <>
+class Compare< int > { // specialization
+public:
+ enum sortCriterion{ increasing, decreasing, absoluteValue };
+ Compare( sortCriterion s = increasing ) : howToSort( s ) { } // Constructor
+ bool operator()( const int& a, const int& b ) const
+ {
+ bool result;
+ switch( howToSort ) {
+ case increasing: result = a < b; break;
+ case decreasing: result = a > b; break;
+ case absoluteValue: result = abs(a) < abs(b); break;
+ default: throw "Compare.operator()(): default darf nicht erreicht werden";
+ }
+ return result;
+ }
+private:
+ sortCriterion howToSort;
+};
+
+int main()
+{
+ Compare< int > absolute( Compare< int >::absoluteValue );
+ SortedList< int > sortedList, sortedListAbsolute( absolute );
+ std::ostream_iterator< int > output( cout, "\t" );
+
+ cout << "Werte mit verschiedenen Vorzeichen einfuegen:\n";
+ for( int i = 0; i < 7; ++i ) {
+ int value = int( 100.0 * sin( static_cast< float >( i ) ) );
+ cout << *sortedList.insert( value ) << endl;
+ sortedListAbsolute.insert( value );
+ }
+
+ cout << "\nincreasing sortiert( default ):\n";
+ std::copy( sortedList.begin(), sortedList.end(), output );
+
+ cout << "\n\nnach Absolutbetrag sortiert:\n";
+ std::copy( sortedListAbsolute.begin(), sortedListAbsolute.end(), output );
+
+ cout << "\n\nWert 90 finden" << endl;
+ SortedList< int >::Iterator search = sortedList.find( 90 );
+ if( search == sortedList.end() )
+ cout << "nicht gefunden\n";
+ else
+ cout << *search << " gefunden" << endl;
+
+ cout << "\nWert 91 finden" << endl;
+ search = sortedList.find( 91 );
+ if( search == sortedList.end() )
+ cout << "nicht gefunden\n\n";
+ else
+ cout << *search << " gefunden" << endl << endl;
+
+ return 0;
+}
+
+