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 "<