From bcf06b63fd6ef0dfa5ce246e5a534a87c6ca33bc Mon Sep 17 00:00:00 2001 From: shivangi Date: Sun, 11 Oct 2020 16:03:40 +0530 Subject: [PATCH 1/2] Hackoberfest 2020 --- .../Moore's_Voting_Algo.cpp | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Problems and General Algos/Moore's_Voting_Algo.cpp diff --git a/Problems and General Algos/Moore's_Voting_Algo.cpp b/Problems and General Algos/Moore's_Voting_Algo.cpp new file mode 100644 index 0000000..13fe7a8 --- /dev/null +++ b/Problems and General Algos/Moore's_Voting_Algo.cpp @@ -0,0 +1,38 @@ +#include +using namespace std; + +//Majority element is the element which appears more than n/2 times in an array, +//where n is the size of the array. + +//Function to calculate the majority element +int fun(vector v){ + //Variable 'ele' to store the majority element + int ele=v[0]; + int k=1; + for(int i=1;i v({3,2,4,3,3,3}); + int ans=fun(v); + int k=0; + for(int i=0;iv.size()/2) + cout<<"Majority element is "< Date: Mon, 12 Oct 2020 15:52:28 +0530 Subject: [PATCH 2/2] adding rainwater trapping --- .../Trapping_rainwater.cpp | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Problems and General Algos/Trapping_rainwater.cpp diff --git a/Problems and General Algos/Trapping_rainwater.cpp b/Problems and General Algos/Trapping_rainwater.cpp new file mode 100644 index 0000000..356ea25 --- /dev/null +++ b/Problems and General Algos/Trapping_rainwater.cpp @@ -0,0 +1,31 @@ +#include +using namespace std; + +int fun(vector& height){ + int n=height.size(); + if(n==0) return 0; + stack s; + int top,distance,length; + int curr=0; + int ans=0; + while(currheight[s.top()]){ + top=s.top(); + s.pop(); + if(s.empty()) + break; + distance=curr-s.top()-1; + length=((height[curr] v({0,1,0,2,1,0,1,3,2,1,2,1}); + cout<<"The amount of trapped rainwater is "<