/*
 * Solution to Problem 3 (C++)
 * 12th Annual CS Programming Contest
 * WCU Dept of Math and CS
 * Copyright 2001 , All Rights Reserved
 *
 * Problem Statement:
 * Unsorted Intersection Check.
 * This program prompts the user for two unsorted arrays of ints.
 * It then determines whether or not either array has an element
 * that is also an element of the other array.
 *
 * This solution uses the brute force approach of nested loops.
 * For each element of the outer array we check to see if there
 * is a match with an element of the inner array. As soon as a
 * match is found, the function returns false (since the function
 * is determining whether the intersection is empty).
 */

#include <iostream.h>
const int NUM_ELTS = 4;

bool isEmpty(int array1[], int array2[])
{
  for (int index1 = 0; index1 < NUM_ELTS; index1++) 
    for (int index2 = 0; index2 < NUM_ELTS; index2++) {
      if (array1[index1] == array2[index2])
        return false;
    }
  return true;
}

int main()
{
  int index;
  bool empty = true;
  int array1[NUM_ELTS]; 
  int array2[NUM_ELTS]; 

  cout << "Each array is five integer values." << endl;
  cout << "Enter the integers for the first array." << endl;
  for (index = 0; index < NUM_ELTS; index++) {
      cin >> array1[index];
  } 
  cout << "Enter the integers for the second array." << endl;
  for (index = 0; index < NUM_ELTS; index++) {
      cin >> array2[index];
  } 
  
  if (isEmpty(array1, array2))
    cout << "The intersection is empty." << endl;
  else
    cout << "The intersection is not empty." << endl;
}


