The Stack Overflow podcast is back! Listen to an interview with our new CEO.
    Post Closed as "off-topic" by Philip Kendall, Ben Cottrell, amon, Bart van Ingen Schenau, Doc Brown
3 added 19 characters in body
source | link
bool IsDoubleString(map<char,int> Word)
{
    bool res = true;
    for (auto itr = Word.begin(); itr != Word.end(); ++itr)
    {
        if (itr->second % 2 != 0)
        {
            itr->second -= 1;
            res = false;
            break;
        }
    }
    if (!res)
    {
        IsDoubleString(Word);
    }
    //return res; should directly return the value to main() but while 
    //debugging I 
    //found it goes inside the if(!res) above this return res; line
    return res;
} 

int main()
{
    map<char, int> WordMap;
    WordMap.insert({ 'w', 2 });
    WordMap.insert({ 'o', 1 });
    IsDoubleString(WordMap) ? cout << "Yes" << endl : cout << "No" << endl;
    return 0;
}

/*The code aims to print Yes or No if from the given string we can divide the string symmetrically, Entered string is P, A+B = P and A=B Print Yes and if we can't divide the string such A is not equal to B we will delete the characters so that we wilL try to make A equal to B
1. wow - Yes, we have to delete o, then A = B = w; P =A+B
2. lala - Yes A = B = la; P = A+B
3. a - No, since we can divide a string of size 1
4. ab - No, if A=a,B=b; A!=B or viceversa
So, the following code works in such a way , We entering a string which is being entered in WordMap, in this scenario we are entering wow string which is inserted in the WordMap and it works perfectly but as soon it returns res; the control goes inside if(!res) but this shouldn't happen as res is true*/

Input: 5 wow tata a ab lala

Output: Yes Yes No No Yes

bool IsDoubleString(map<char,int> Word)
{
    bool res = true;
    for (auto itr = Word.begin(); itr != Word.end(); ++itr)
    {
        if (itr->second % 2 != 0)
        {
            itr->second -= 1;
            res = false;
            break;
        }
    }
    if (!res)
    {
        IsDoubleString(Word);
    }
    //return res; should directly return the value to main() but while 
    //debugging I 
    //found it goes inside the if(!res) above this return res; line
    return res;
}

Input: 5 wow tata a ab lala

Output: Yes Yes No No Yes

bool IsDoubleString(map<char,int> Word)
{
    bool res = true;
    for (auto itr = Word.begin(); itr != Word.end(); ++itr)
    {
        if (itr->second % 2 != 0)
        {
            itr->second -= 1;
            res = false;
            break;
        }
    }
    if (!res)
    {
        IsDoubleString(Word);
    }
    //return res; should directly return the value to main() but while 
    //debugging I 
    //found it goes inside the if(!res) above this return res; line
    return res;
} 

int main()
{
    map<char, int> WordMap;
    WordMap.insert({ 'w', 2 });
    WordMap.insert({ 'o', 1 });
    IsDoubleString(WordMap) ? cout << "Yes" << endl : cout << "No" << endl;
    return 0;
}

/*The code aims to print Yes or No if from the given string we can divide the string symmetrically, Entered string is P, A+B = P and A=B Print Yes and if we can't divide the string such A is not equal to B we will delete the characters so that we wilL try to make A equal to B
1. wow - Yes, we have to delete o, then A = B = w; P =A+B
2. lala - Yes A = B = la; P = A+B
3. a - No, since we can divide a string of size 1
4. ab - No, if A=a,B=b; A!=B or viceversa
So, the following code works in such a way , We entering a string which is being entered in WordMap, in this scenario we are entering wow string which is inserted in the WordMap and it works perfectly but as soon it returns res; the control goes inside if(!res) but this shouldn't happen as res is true*/
2 added 19 characters in body
source | link

In the following function IsDoubleString(),if res is true then it shouldn't call IsDoubleString(), I debugged the code but I am unable to understand that once it hit the line returns res; why does the control go inside the if(!res) condition? Shouldn't it be directly returning the res value to the main function?

bool IsDoubleString(map<char,int> Word)
{
    bool res = true;
    for (auto itr = Word.begin(); itr != Word.end(); ++itr)
    {
        if (itr->second % 2 != 0)
        {
            itr->second -= 1;
            res = false;
            break;
        }
    }
    if (!res)
    {
        IsDoubleString(Word);
    }
    //Thisreturn res; should directly return the value to main() but while 
    //debugging I 
    //found it goes inside the if(!res) above this return res; line
    return res;
}

Input: 5 wow tata a ab lala

Output: Yes Yes No No Yes

In the following function IsDoubleString(),if res is true then it shouldn't call IsDoubleString(), I debugged the code but I am unable to understand that once it hit the line returns res; why does the control go inside the if(!res) condition? Shouldn't it be directly returning the res value to the main function?

bool IsDoubleString(map<char,int> Word)
{
    bool res = true;
    for (auto itr = Word.begin(); itr != Word.end(); ++itr)
    {
        if (itr->second % 2 != 0)
        {
            itr->second -= 1;
            res = false;
            break;
        }
    }
    if (!res)
    {
        IsDoubleString(Word);
    }
    //This should directly return the value to main() but while debugging I 
    //found it goes inside the if(!res) above this return res; line
    return res;
}

Input: 5 wow tata a ab lala

Output: Yes Yes No No Yes

In the following function IsDoubleString(),if res is true then it shouldn't call IsDoubleString(), I debugged the code but I am unable to understand that once it hit the line returns res; why does the control go inside the if(!res) condition? Shouldn't it be directly returning the res value to the main function?

bool IsDoubleString(map<char,int> Word)
{
    bool res = true;
    for (auto itr = Word.begin(); itr != Word.end(); ++itr)
    {
        if (itr->second % 2 != 0)
        {
            itr->second -= 1;
            res = false;
            break;
        }
    }
    if (!res)
    {
        IsDoubleString(Word);
    }
    //return res; should directly return the value to main() but while 
    //debugging I 
    //found it goes inside the if(!res) above this return res; line
    return res;
}

Input: 5 wow tata a ab lala

Output: Yes Yes No No Yes

1
source | link

Exiting Recursive Function C++

In the following function IsDoubleString(),if res is true then it shouldn't call IsDoubleString(), I debugged the code but I am unable to understand that once it hit the line returns res; why does the control go inside the if(!res) condition? Shouldn't it be directly returning the res value to the main function?

bool IsDoubleString(map<char,int> Word)
{
    bool res = true;
    for (auto itr = Word.begin(); itr != Word.end(); ++itr)
    {
        if (itr->second % 2 != 0)
        {
            itr->second -= 1;
            res = false;
            break;
        }
    }
    if (!res)
    {
        IsDoubleString(Word);
    }
    //This should directly return the value to main() but while debugging I 
    //found it goes inside the if(!res) above this return res; line
    return res;
}

Input: 5 wow tata a ab lala

Output: Yes Yes No No Yes