Q:

how to write a cleaner comparison

Hi I'm not familiar with algorithm, so I'm asking help for this simple comparison. So I have two unsigned int arrays with size N. and I need to compare which one is bigger. How I compare is I start from the left element, and if A[i] is bigger than B[i], then A array > B array.if they are equal, I compare A[i+1] and B[i+1]. A brut force way to do so is:
BOOL checkArray(int[] A, int[] B) {
    for(i=0; i< N; i ++){ 
       if (A[i] > B[i]) {
           return TRUE;
       }else if (A[i] == B[i]) {
           continue;
       } else {  \\ A[i] < B[i]
           return FALSE;
       }
    }
}

Please advise if there's a better way to achieve this. Thanks a lot !!!

A:

Look at the standard library's implementation of strcmp.
bool checkArray (int [] a, int [] b)
{
  int
     i = 0;

  while (i < N && a [i] == b [i])
  {
    ++i;
  }

  return i < N && a [i] > b [i]; // return false if arrays equal
  //return i >= N || a [i] > b [i]; // return true if arrays equal
}

Your example code, however, has a route out of the function that is undefined - that is, is all elements of A are equal to all elements of B.

