From 5f595b9ba9ca791b0c0fa7dfde6780643694f85f Mon Sep 17 00:00:00 2001 From: Tuhin1500 <109733875+Tuhin1500@users.noreply.github.com> Date: Tue, 24 Oct 2023 23:36:09 +0530 Subject: [PATCH] Updated the code efficiently BogoSort.cpp Removed the unnecessary inclusion of the header because it was not being used in your code. Added code to generate random data and populate the vector, ensuring that the random data generation process is properly implemented. Improved the output formatting by adding newline characters for better readability in the console output. --- BogoSort.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/BogoSort.cpp b/BogoSort.cpp index b5f4969..530c976 100644 --- a/BogoSort.cpp +++ b/BogoSort.cpp @@ -29,8 +29,16 @@ void quickSort(std::vector& arr, int low, int high) { } int main() { - // Generate random data - std::vector data = {5, 2, 9, 1, 5, 6}; + // Generate random data and populate the vector + int n = 6; // Adjust the size as needed + std::random_device rd; + std::mt19937 generator(rd()); + std::uniform_int_distribution distribution(1, 100); // Adjust the range as needed + std::vector data; + + for (int i = 0; i < n; ++i) { + data.push_back(distribution(generator)); + } std::cout << "Unsorted array: "; for (int num : data) { @@ -38,7 +46,6 @@ int main() { } std::cout << std::endl; - int n = data.size(); quickSort(data, 0, n - 1); std::cout << "Sorted array: "; @@ -49,4 +56,3 @@ int main() { return 0; } -