From 16cf757d7c34a7d57c33369f35e91e73949f1074 Mon Sep 17 00:00:00 2001 From: 2019pgcaca31 <72298801+2019pgcaca31@users.noreply.github.com> Date: Tue, 26 Oct 2021 13:59:20 +0530 Subject: [PATCH] Create bubble sort --- bubble sort | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 bubble sort diff --git a/bubble sort b/bubble sort new file mode 100644 index 0000000..708ac83 --- /dev/null +++ b/bubble sort @@ -0,0 +1,51 @@ + +#include +using namespace std; + +int bulbs(int a[],int n) +{ + int count = 0; + + int res = 0; + for (int i = 0; i < n; i++) + { + + + + if (a[i] == 1 && count % 2 == 0) + continue; + + + + + else if(a[i] == 0 && count % 2 != 0) + continue; + + + + + + else if (a[i] == 1 && count % 2 != 0) + { + res++; + count++; + } + + + + + + else if (a[i] == 0 && count % 2 == 0) + { + res++; + count++; + } + } + return res; +} +int main() +{ + int states[] = {1,1,0,0,1,1,0,1,1,1}; + int n = sizeof(states)/sizeof(states[0]); + cout << "The minimum number of switches needed are " << bulbs(states,n); +}