diff --git a/sorting/bubble_sort2.cpp b/sorting/bubble_sort2.cpp new file mode 100644 index 0000000000..e681aba417 --- /dev/null +++ b/sorting/bubble_sort2.cpp @@ -0,0 +1,47 @@ + +#include +using namespace std; + +/** + * @file + * @brief Simplified implementation of Bubble Sort + * + * @details + * This code takes input from the user and applies the Bubble Sort algorithm + * to sort the given array in ascending order. It is a beginner-friendly + * version written using basic C++ without advanced templates or libraries. + */ + +/** + * @brief Main function to run the Bubble Sort + * @return 0 on successful execution + */ + +int main(){ + int n,t; + //input array size + cout<<"enter size"; + cin>>n; + int arr[n]; + + //input array elements + cout<<"enter elements"; + for(int i=0;i>arr[i]; + } + for(int j=0;jarr[k+1]){ + //swap elements + t=arr[k]; + arr[k]=arr[k+1]; + arr[k+1]=t; + } + } + } + //output the sorted array + for(int l=0;l