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;
}
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
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.