diff --git a/Sortieralgorithmen/InsertionSort.cpp b/Sortieralgorithmen/InsertionSort.cpp index 7ef69e4..a59712e 100644 --- a/Sortieralgorithmen/InsertionSort.cpp +++ b/Sortieralgorithmen/InsertionSort.cpp @@ -2,6 +2,8 @@ #include #include #include +#include +#include int main() { @@ -12,21 +14,32 @@ int main() getline(std::cin, input); std::stringstream(input) >> amount; - std::cout << "\n"; - long double array[amount]; - for(unsigned short idx = 0; idx < amount; idx++) + std::cout << "\nM\x94 \bchtest du mit zuf\x84lligen Zahlen arbeiten? y/n "; + getline(std::cin, input); + if(input == "y" || input == "Y") { - std::cout << "Gib die " << idx+1 << ". Zahl ein: "; - getline(std::cin,input); - std::stringstream(input) >> array[idx]; + srand(time(0)); + for(unsigned short idx = 0; idx < amount; idx++) + { + array[idx] = rand()%100; + } + } + else + { + 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 #include #include +#include +#include int main() { @@ -12,15 +14,26 @@ int main() getline(std::cin, input); std::stringstream(input) >> amount; - std::cout << "\n"; - long double array[amount]; - for(unsigned short idx = 0; idx> array[idx]; + srand(time(0)); + for(unsigned short idx = 0; idx < amount; idx++) + { + array[idx] = rand()%100; + } + } + else + { + 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";