diff --git a/.github/workflows/example-workflow.yml b/.github/workflows/example-workflow.yml index 67c6860..2bb0690 100644 --- a/.github/workflows/example-workflow.yml +++ b/.github/workflows/example-workflow.yml @@ -5,6 +5,7 @@ on: - main pull_request: types: [opened, synchronize, reopened] + workflow_dispatch: {} jobs: test: runs-on: ubuntu-22.04-arm diff --git a/bubble_sort.cpp b/bubble_sort.cpp index 7beecde..8a5ec22 100644 --- a/bubble_sort.cpp +++ b/bubble_sort.cpp @@ -1,5 +1,6 @@ #include #include +#include // BubbleSort sorts a vector of integers using the bubble sort algorithm void bubbleSort(std::vector& arr) { @@ -16,20 +17,49 @@ void bubbleSort(std::vector& arr) { } } +// SlowBubbleSort is an inefficient bubble sort that always performs all comparisons +void slowBubbleSort(std::vector& arr) { + int n = arr.size(); + for (int i = 0; i < n; i++) { + for (int j = 0; j < n - 1; j++) { + if (arr[j] > arr[j + 1]) { + // Swap adjacent elements + int temp = arr[j]; + arr[j] = arr[j + 1]; + arr[j + 1] = temp; + } + } + } +} + int main() { - std::vector numbers = {64, 34, 25, 12, 22, 11, 90}; + // Generate random size between 100 and 100000 + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> sizeDistr(100, 100000); + int size = sizeDistr(gen); + + // Create a dynamic vector at runtime with random size + std::vector dynamicVector(size); + + // Fill vector with random values + std::uniform_int_distribution<> valueDistr(1, 1000); + for (int i = 0; i < size; i++) { + dynamicVector[i] = valueDistr(gen); + } - std::cout << "Original array: "; - for (int num : numbers) { - std::cout << num << " "; + std::cout << "Generated vector of size: " << size << std::endl; + std::cout << "First 10 elements: "; + for (int i = 0; i < std::min(10, size); i++) { + std::cout << dynamicVector[i] << " "; } std::cout << std::endl; - bubbleSort(numbers); + bubbleSort(dynamicVector); - std::cout << "Sorted array: "; - for (int num : numbers) { - std::cout << num << " "; + std::cout << "Sorted! First 10 elements: "; + for (int i = 0; i < std::min(10, size); i++) { + std::cout << dynamicVector[i] << " "; } std::cout << std::endl;