Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool Overlap(Int* arrayA, Int* arrayB, Int sizeA, Int sizeB)
- {
- // Find out which one is preceeding the other, i.e., uses a smaller address
- if(arrayB < arrayA)
- {
- // Swap the addresses and sizes if B is preceeding A
- Int* tempArray = arrayA;
- arrayA = arrayB;
- arrayB = tempArray;
- //--//
- Int tempSize = sizeA;
- sizeA = sizeB;
- sizeB = tempSize;
- }
- // Check if the last element of the preceeding array is below the first element of the proceeding array
- if(&arrayA[sizeA] > &arrayB[0])
- {
- // If so, then part of the first array exists in the second array
- return true;
- }
- else
- {
- // Otherwise, they exist in different areas of memory
- return false;
- }
- }
- bool Overlap(Int* arrayA, Int* arrayB, Int sizeA, Int sizeB)
- {
- // Iterate through both arrays
- for(Int j = 0; j < sizeB; ++j)
- {
- for(Int i = 0; i < sizeA; ++i)
- {
- // Check if any of the elements equal another element in the other array
- if(arrayA[i] == arrayB[j])
- {
- return true;
- }
- }
- }
- // If not, then none of the elements overlap
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement