diff --git a/Sorting/Bubble Sort/C++/Bubble_Sort_3.cpp b/Sorting/Bubble Sort/C++/Bubble_Sort_3.cpp index 29b6b916..8e5b1e4f 100644 --- a/Sorting/Bubble Sort/C++/Bubble_Sort_3.cpp +++ b/Sorting/Bubble Sort/C++/Bubble_Sort_3.cpp @@ -1,41 +1,65 @@ #include using namespace std; -void bubbleSort(int A[],int n) -{ - int i,j; - int temp; - for(i=0;i array[j+1]){ + swap(array[j+1], array[j]); + flag = 1; } + } + if(flag == 0){ + break; + } } -} + } -int main() -{ - int n; - cout<<"Enter the size of the array\n"; - cin>>n; - int a[n]; - cout<<"Enter the element\n"; - for(int i=0;i>a[i]; - } - bubbleSort(a,n); - cout<<"The Sorted array is :-"; - for(int i=0;i> 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:" <