1. ## Array Comparisons

I'm self learning C++ to make myself more valuable to my bosses.
I'm using Microsoft Visual C++ 5.0.
I am trying to create random numbers in multiple arrays, comparing the new array elements to previously set array elements to make sure there are no two elements with the same value. This gets really long and hard to follow using 'if' and comparison statements. My question is: Is there a function to compare the elements of 2 arrays (type int for this example)?

2. >Is there a function to compare the elements of 2 arrays (type int for this example)?
Yes. But you'll have to write it yourself. It shouldn't be too hard though:
Code:
```bool acmp ( const int array1[], const int array2[], int size )
{
for ( int i = 0; i < size; i++ ) {
if ( array1[i] != array2[i] )
return false;
}
return true;
}```

3. I have done that, but it appears to only check elements of equal position, meaning if array1[0] == array2[5], it wouldn't get checked and I would not know about it.

4. >meaning if array1[0] == array2[5], it wouldn't get checked and I would not know about it.
Then use two loops. One goes over array1 and the other goes over array2. Something like this:
Code:
```bool intersect ( const int array1[], const int array2[], int size )
{
for ( int i = 0; i < size; i++ ) {
for ( int j = 0; j < size; j++ ) {
if ( array1[i] == array2[j] )
return true; // Item in array1 found in array2
}
}
return false;
}```

5. Thank You kindly, I got it working, and I managed to get the function to sort the arrays in ascending order without further help, maybe there's hope for me yet?

6. ## Comparing 3 numbers and returning largest

I need to figure out how you would compare 3 numbers and sort from smallest to largest. I'll be using an overloaded operator, < to do this, but that part I can figure out. I just need to know the syntax for sorting and returning them in order from smallest to largest.
Thanx.
DD.

7. How would you do this by hand?

One way is to say is A < B and A < C? If so then A is smallest. Else is B < A and B < C? if so then B is smallest. Else is C < A and C < B? if so then C is smallest. etc.

Another way, is create a temporary variable called smallest. Assign A to smallest. Compare smallest to B. If B is smaller than smallest then assign B to smallest. Then compare smallest with C. If C is smaller than smallest then assign C to smallest. etc.

Another way is to put all three values in an array. Then compare array[2] with array[1]. If array[2] < array[1], swap values. Then compare array[1] with array[0]. If array[1] < array[0], then swap. etc.

Lot's of ways to do this. Depends on what you know already, and what you are learning about now. Give it your best shot and come back with more precise questions if you need to.

8. Ok, I can understand that, but that will just give me the smallest...how do I go about printing out the smallest to largest?
DD

9. Code:
```version 1.  if a < b and a < c
if b < c
cout a b c
else
cout  a c b
else if b < a and b < c
if a < c
cout b a c
else
cout b c a
etc.

version 2.   if a = = smallest
if b < c
etc

version 3.  look up bubble sort by searching the board or the web or your instructional book.  its a general sort algorhythm that will work for array/list of any size and not specific to just three values, like version 1 and 2.  It can also be used to sort largest to smallest.  It's not the most sophisticated sorting algorhythm, and for larger groups of values it's not the fastest, but it is among the easiest code to write.```