From bcf06b63fd6ef0dfa5ce246e5a534a87c6ca33bc Mon Sep 17 00:00:00 2001 From: shivangi Date: Sun, 11 Oct 2020 16:03:40 +0530 Subject: [PATCH] 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 "<