Find even occurring elements in an array of limited range | C ++ Program to find the even occurring elements in given array ; Function to find the even occurring elements in given array ; do for each element of array ; left - shift 1 by value of current element ; Toggle the bit everytime element gets repeated ; Traverse array again and use _xor to find even occurring elements ; left - shift 1 by value of current element ; Each 0 in _xor represents an even occurrence ; print the even occurring numbers ; set bit as 1 to avoid printing duplicates ; Driver code
#include <iostream> NEW_LINE using namespace std ; void printRepeatingEven ( int arr [ ] , int n ) { long long _xor = 0L ; long long pos ; for ( int i = 0 ; i < n ; ++ i ) { pos = 1 << arr [ i ] ; _xor ^= pos ; } for ( int i = 0 ; i < n ; ++ i ) { pos = 1 << arr [ i ] ; if ( ! ( pos & _xor ) ) { cout << arr [ i ] << " ▁ " ; _xor ^= pos ; } } } int main ( ) { int arr [ ] = { 9 , 12 , 23 , 10 , 12 , 12 , 15 , 23 , 14 , 12 , 15 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printRepeatingEven ( arr , n ) ; return 0 ; }