diff --git a/Sortieralgorithmen/BubbleSort.cpp b/Sortieralgorithmen/BubbleSort.cpp new file mode 100644 index 0000000..db269af --- /dev/null +++ b/Sortieralgorithmen/BubbleSort.cpp @@ -0,0 +1,87 @@ +#include +#include +#include +#include +#include +#include + +void BubbleSort(long double *array, unsigned short amount); +void BubbleSort(int *array, unsigned short amount); + +int main() +{ + std::string input; + unsigned short amount = 1; + + std::cout << "Gib die Anzahl der Zahlen ein: "; + getline(std::cin, input); + std::stringstream(input) >> 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()%1000; + BubbleSort(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]; + } + BubbleSort(array, amount); + delete[] array; + } + + getch(); + return(0); +} + +void BubbleSort(int *array, unsigned short amount) +{ + std::cout << "\n"; + + for(unsigned short idx = 0; idx+1idx; idx2--) if(array[idx2]idx; idx2--) if(array[idx2]