diff --git a/655282/BubbleSort.cpp b/655282/BubbleSort.cpp new file mode 100644 index 0000000..213fe85 --- /dev/null +++ b/655282/BubbleSort.cpp @@ -0,0 +1,33 @@ +#include +using namespace std; + +int main() { + int count; + cin >> count; + + int nums[count]; + for (int i = 0; i < count; i++) { + cin >> nums[i]; + } + + for (int i = 0; i < count; i++) { + int low = nums[i]; + if (nums[i] < low) { + low = nums[i]; + } + } + + for (int j = count; j > 0; j--) { + for (int i = 0; i < j - 1; i++) { + if (nums[i] > nums[i + 1]) { + int save = nums[i]; + nums[i] = nums[i + 1]; + nums[i + 1] = save; + } + } + } + + for (int i = 0; i < count; i++) { + cout << nums[i] << "\n"; + } +} diff --git a/655282/BubbleSortNew.cpp b/655282/BubbleSortNew.cpp new file mode 100644 index 0000000..00d0a1c --- /dev/null +++ b/655282/BubbleSortNew.cpp @@ -0,0 +1,32 @@ +#include +using namespace std; + +void swap(int *m, int *n); + +int main() { + int count; + cin >> count; + + int nums[count]; + for (int i = 0; i < count; i++) { + cin >> nums[i]; + } + + for (int j = count; j > 0; j--) { + for (int i = 0; i < j - 1; i++) { + if (nums[i] > nums[i + 1]) { + swap(&nums[i], &nums[i + 1]); + } + } + } + + for (int i = 0; i < count; i++) { + cout << nums[i] << "\n"; + } +} + +void swap(int *m, int *n) { + int temp = *m; + *m = *n; + *n = temp; +}