diff --git a/Sortieralgorithmen/SelectionSort.cpp b/Sortieralgorithmen/SelectionSort.cpp index 6f0ddea..a229754 100644 --- a/Sortieralgorithmen/SelectionSort.cpp +++ b/Sortieralgorithmen/SelectionSort.cpp @@ -5,6 +5,9 @@ #include #include +void SelectionSort(long double *array, unsigned short amount); +void SelectionSort(int *array, unsigned short amount); + int main() { std::string input; @@ -14,28 +17,59 @@ int main() getline(std::cin, input); std::stringstream(input) >> amount; - long double array[amount]; - std::cout << "\nM\x94 \bchtest du mit zuf\x84lligen Zahlen arbeiten? y/n "; getline(std::cin, input); if(input == "y" || input == "Y") { + int *array = new int[amount]; srand(time(0)); - for(unsigned short idx = 0; idx < amount; idx++) - { - array[idx] = rand()%100; - } + for(unsigned short idx = 0; idx < amount; idx++) array[idx] = rand()%100; + SelectionSort(array, amount); + delete[] array; } else { + long double *array = new long double[amount]; for(unsigned short idx = 0; idx < amount; idx++) { std::cout << "Gib die " << idx+1 << ". Zahl ein: "; getline(std::cin,input); std::stringstream(input) >> array[idx]; } + SelectionSort(array, amount); + delete[] array; } + getch(); + return(0); +} + +void SelectionSort(long double *array, unsigned short amount) +{ + std::cout << "\n"; + + for(unsigned short idx =0; idx