Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

whats wrong with my code? ------- bool sameSet(const int *aBeg, const int *aEnd,

ID: 3601610 • Letter: W

Question

whats wrong with my code?

-------

bool sameSet(const int *aBeg, const int *aEnd,
const int *bBeg, const int *bEnd)
{
// Add your code yere
while (aBeg != aEnd)
{
while(bBeg != bBeg)
{
if(*aBeg != *bBeg)
{
return false;
}
else
return true;
bBeg++;
}
aBeg++;

}

return true;
}

Checking function: sameSet +For input of ARRAY (111}), ARRAY (111, 11, 11)) +For input of ARRAY (1, 4, 9, 16, 9, 7, 4, 9, 11}), ARRAY (111, 11, 7, 9, 16, 4, 1)) X For input of ARRAY (1, 4, 1}), ARRAY (11, 11, 7, 9, 16, 4, 1}) should be false, but is true. X For input of ARRAY (1, 1, 11}), ARRAY (111, 11, 7) should be false, but is true. X For input of ARRAY (1, 4, 9, 16), ARRAY (19, 4, 1,}) should be false, but is true. +For input of ARRAY (111, 11}), ARRAY (11)) X For input of ARRAY (1, 4, 9, 16), ARRAY (19, 4, 1,}) should be false, but is true. +For input of ARRAY (111, 11, 550, 650}), ARRAY (f11, 550, 550, 650, 550)) +For input of ARRAY (111, 11, 11, 11, 2), ARRAY (12,2,2,11}) X For input of ARRAY (1, 4, 91), ARRAY (9, 4, 1,16) should be false, but is true. Tests passing 5/10 (50%).

Explanation / Answer

bool sameSet(const int* aBeg, const int* aEnd,
    const int* bBeg, const int* bEnd)
{
    // Add your code yere
    while (aBeg != aEnd) {
        if (*aBeg != *bBeg) {   // check if value at current position is equal on both sides
            return false;       // if else, stop processing further and return false
        }
        bBeg++;       // increment both pointers
        aBeg++;
    }
    return true; // if all elements until the end matched, return true
}