From e583c9ff834ffcaa7353e1d2e5d5df3e5aa69cd8 Mon Sep 17 00:00:00 2001 From: Leaced Date: Sun, 9 Apr 2017 14:00:28 +0200 Subject: [PATCH] dynamischer Speicher --- Sortieralgorithmen/InsertionSort.cpp | 73 +++++++++++++++++++--------- 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/Sortieralgorithmen/InsertionSort.cpp b/Sortieralgorithmen/InsertionSort.cpp index a59712e..9bd3b2c 100644 --- a/Sortieralgorithmen/InsertionSort.cpp +++ b/Sortieralgorithmen/InsertionSort.cpp @@ -5,6 +5,9 @@ #include #include +void InsertionSort(long double *ptr, unsigned short amount); +void InsertionSort(int *ptr, unsigned short amount); + int main() { std::string input; @@ -14,45 +17,69 @@ 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; + InsertionSort(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]; } - } - - std::cout << "\n"; - - for(unsigned short idx = 0; idx=0 && array[idx2]>temp) array[idx2+1] = array[idx2--]; - array[idx2+1] = temp; - - for(unsigned short idx =0; idx=0 && ptr[idx2]>temp) ptr[idx2+1] = ptr[idx2--]; + ptr[idx2+1] = temp; + + for(unsigned short idx =0; idx=0 && ptr[idx2]>temp) ptr[idx2+1] = ptr[idx2--]; + ptr[idx2+1] = temp; + + for(unsigned short idx =0; idx