Code implement power function in O(log n) time complexity

Algorithm/Flowchart (For programming based labs): 

• Step 1: let x and positive y are two number. 

• Step 2: check if y==0 return 1 && y%2==0 return power()*power. 

• Step 3: else return x*power()*power(). 

• Step 4: Repeat. 

• Step 5: power(x,y). 

• Step 6: finish

#include <iostream>
using namespace std;
class gfg
{
public:
    int power(int x, unsigned int y)
    {
        if (y == 0)
            return 1;
        else if (y % 2 == 0)
            return power(x, y / 2) * power(x, y / 2);
        else
            return x * power(x, y / 2) * power(x, y / 2);
    }
};
int main()
{
    gfg g;
    int x = 7;
    unsigned int y = 2;
    cout << g.power(x, y);
    return 0;
}