From c4ce8fd4f33335a2a7763c0afec5628a5bdc9d73 Mon Sep 17 00:00:00 2001 From: Sharmistha Mandal <65134125+Sharmi-1999@users.noreply.github.com> Date: Thu, 1 Oct 2020 19:42:59 +0530 Subject: [PATCH 1/3] Add files via upload --- Sorting/bubble.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Sorting/bubble.cpp diff --git a/Sorting/bubble.cpp b/Sorting/bubble.cpp new file mode 100644 index 0000000..ae713e5 --- /dev/null +++ b/Sorting/bubble.cpp @@ -0,0 +1,46 @@ +#include +#include +using namespace std; + +void bubble_sort(int a[],int n) +{ + int flag,p=0; + for(int i=0;ia[j+1]) + { + swap(a[j],a[j+1]); + flag=1; + p++; + } + } + if(flag==0) + { + break; + } + } + + cout<<"Array is sorted in"<<" "<>n; + int a[n]; + for(int i=0;i>a[i]; + } + bubble_sort(a,n); + cout<<"Sorted array is:"<<" "; + for(int i=0;i Date: Thu, 1 Oct 2020 19:47:19 +0530 Subject: [PATCH 2/3] Update and rename bubble.cpp to bubble_Sort.cpp --- Sorting/{bubble.cpp => bubble_Sort.cpp} | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) rename Sorting/{bubble.cpp => bubble_Sort.cpp} (66%) diff --git a/Sorting/bubble.cpp b/Sorting/bubble_Sort.cpp similarity index 66% rename from Sorting/bubble.cpp rename to Sorting/bubble_Sort.cpp index ae713e5..910da36 100644 --- a/Sorting/bubble.cpp +++ b/Sorting/bubble_Sort.cpp @@ -1,3 +1,9 @@ + +Best Case Time Complexity: O(n). Best case occurs when array is already sorted. +Worst and Average Case Time Complexity: O(n^2). Worst case occurs when array is reverse sorted. + +Auxiliary Space: O(1) + #include #include using namespace std; @@ -44,3 +50,13 @@ int main() { } return 0; } + + +// Input: +// 4 +// 3 12 4 2 +// Output: +// Array is sorted in 4 swaps. +// First Element: 2 +// Last Element: 12 +// Sorted array is: 2 3 4 12 From f9958ca1091a90ef91b554e1851e78f8098adb98 Mon Sep 17 00:00:00 2001 From: Sharmistha Mandal <65134125+Sharmi-1999@users.noreply.github.com> Date: Thu, 1 Oct 2020 19:55:43 +0530 Subject: [PATCH 3/3] Update bubble_Sort.cpp --- Sorting/bubble_Sort.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sorting/bubble_Sort.cpp b/Sorting/bubble_Sort.cpp index 910da36..52c1a72 100644 --- a/Sorting/bubble_Sort.cpp +++ b/Sorting/bubble_Sort.cpp @@ -1,8 +1,8 @@ -Best Case Time Complexity: O(n). Best case occurs when array is already sorted. -Worst and Average Case Time Complexity: O(n^2). Worst case occurs when array is reverse sorted. +// Best Case Time Complexity: O(n). Best case occurs when array is already sorted. +// Worst and Average Case Time Complexity: O(n^2). Worst case occurs when array is reverse sorted. -Auxiliary Space: O(1) +// Auxiliary Space: O(1) #include #include