diff --git a/Bubble-Sort.cpp b/Bubble-Sort.cpp index ec9848d..9fb6c89 100644 --- a/Bubble-Sort.cpp +++ b/Bubble-Sort.cpp @@ -1,39 +1,67 @@ -#include -#include - +#include using namespace std; -int data[1000]; - -void bubble_sort(int *d, int n) -{ - for (int k = 1; k < n; k++) - { - for (int i = 1; i < n; i++) - { - if (d[i] < d[i - 1]) - { - int temp = d[i]; - d[i] = d[i - 1]; - d[i - 1] = temp; - } - } - } +void bubbleSort(int array[], int size, int order){ + + if(order == 1){ + for(int i=0; i < size-1; i++){ + int flag = 0; + + for(int j=0; j array[j+1]){ + swap(array[j+1], array[j]); + flag = 1; + } + } + + if(flag == 0){ + break; + } + } + } + + else if(order == 2){ + for(int i=0; i < size-1; i++){ + int flag = 0; + + for(int j=0; j> size; + + int array[size]; + + cout << "Enter the elements of the array:" << endl; + for(int i = 0; i < size; i++){ + cin >> array[i]; + } + + cout << "What type of ordering do you want: \n 1 - Ascending \n 2 - Descending" << endl; + cin >> order; + + bubbleSort(array, size, order); + + cout << "The sorted array is:" <