A C++ implementation of the bubble sort algorithm, converted from Go with comprehensive test coverage.
- bubble_sort.cpp - Main program demonstrating the bubble sort algorithm
- test_bubble_sort.cpp - Comprehensive test suite with 8 test cases
- Makefile - Build configuration for compilation and testing
Build all targets:
makeBuild individual targets:
make bubble_sort # Build main program
make test_bubble_sort # Build test executablemake bubble_sort
./bubble_sortOutput:
Original array: 64 34 25 12 22 11 90
Sorted array: 11 12 22 25 34 64 90
make testThe test suite includes:
- ✓ Already sorted array
- ✓ Reverse sorted array
- ✓ Random array
- ✓ Single element
- ✓ Two elements
- ✓ Array with duplicates
- ✓ Empty array
- ✓ Negative numbers
All tests should pass with output showing each test case.
Bubble Sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. The pass through the list is repeated until the list is sorted.
Time Complexity: O(n²) Space Complexity: O(1)
- C++ Standard: C++11
- Compiler: g++
- Flags: -Wall -Wextra (warnings enabled)
Remove compiled binaries:
make clean- g++ compiler
- make build tool
- Standard C++ library