summaryrefslogtreecommitdiffstats
path: root/Bachelor/Prog2/SortedList/sortedList1.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/sortedList1.cpp
downloadStudium-master.tar.gz
Studium-master.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Bachelor/Prog2/SortedList/sortedList1.cpp')
-rw-r--r--Bachelor/Prog2/SortedList/sortedList1.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/Bachelor/Prog2/SortedList/sortedList1.cpp b/Bachelor/Prog2/SortedList/sortedList1.cpp
new file mode 100644
index 0000000..f0b548b
--- /dev/null
+++ b/Bachelor/Prog2/SortedList/sortedList1.cpp
@@ -0,0 +1,80 @@
+// List class test program for sorted list
+
+#include <iostream>
+using std::cin;
+using std::endl;
+
+#include <string>
+using std::string;
+
+#include "list.h" // List class definition
+
+// function to test a List
+template< class T >
+void testList( List< T > &listObject, const string &typeName )
+{
+ cout << "Testing a List of " << typeName << " values\n";
+
+ instructions(); // display instructions
+
+ int choice;
+ T value;
+
+ do {
+ cout << "? ";
+ cin >> choice;
+
+ switch ( choice ) {
+ case 1:
+ cout << "Enter " << typeName << ": ";
+ cin >> value;
+ listObject.insertInOrder( value );
+ listObject.print();
+ break;
+
+ case 2:
+ if ( listObject.removeFromFront( value ) )
+ cout << value << " removed from list\n";
+
+ listObject.print();
+ break;
+
+ case 3:
+ if ( listObject.removeFromBack( value ) )
+ cout << value << " removed from list\n";
+
+ listObject.print();
+ break;
+
+ } // end switch
+
+ } while ( choice != 5 ); // end do/while
+
+ cout << "End list test\n\n";
+
+} // end function testList
+
+// display program instructions to user
+void instructions()
+{
+ cout << "Enter one of the following:\n"
+ << " 1 to insert in sorted order into the list\n"
+ << " 2 to delete from beginning of list\n"
+ << " 3 to delete from end of list\n"
+ << " 5 to end list processing\n";
+
+} // end function instructions
+
+int main()
+{
+ // test List of int values
+ List< int > integerList;
+ testList( integerList, "integer" );
+
+ // test List of double values
+ List< double > doubleList;
+ testList( doubleList, "double" );
+
+ return 0;
+
+} // end main \ No newline at end of file