From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- Bachelor/Prog1/Prakt4/prg1p4_2/main.cpp | 123 ++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 Bachelor/Prog1/Prakt4/prg1p4_2/main.cpp (limited to 'Bachelor/Prog1/Prakt4/prg1p4_2/main.cpp') diff --git a/Bachelor/Prog1/Prakt4/prg1p4_2/main.cpp b/Bachelor/Prog1/Prakt4/prg1p4_2/main.cpp new file mode 100644 index 0000000..6c30139 --- /dev/null +++ b/Bachelor/Prog1/Prakt4/prg1p4_2/main.cpp @@ -0,0 +1,123 @@ +// Programmieren 1, Praktikum 4, Aufgabe 2 +// Sven Eisenhauer +// 08.12.2004 +// +// file: main.cpp +// +// purpose: Implementation of Selection Sort and Insertion Sort algorithm +// + +#include + +using std::cout; +using std::endl; + +#include + +using std::setprecision; +using std::setw; + +// contains function prototypes for functions srand and rand +#include + +#include + +void selectionSort(int[], int); +void insertionSort(int[], int); + +int main () +{ + const int arraySize=5; + int array1[arraySize],array2[arraySize]; + + srand(time(0)); + + // fill the arrays with some random stuff + for (int i=0;i= 0)) + { + // always copy the value from the array field before + // so the gap "walks" to the left, until a[i] is at the right place + // and we can put temp in it. + a[i+1]=a[i]; + i--; + } + // i+1 to compensate the last i--, because we want a[i] before the last i-- + a[i+1]=temp; + } + + } +} // end function insertionSort \ No newline at end of file -- cgit v1.2.3