Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The algorithm is O(n), but you are assuming that the arrays are equally sized and each one has a size of <code>ARY_SIZE</code>.</p> <p>I will not solve the entire homework for you, but I suggest you start with the following function header: <code>int compar2arr(int arrA[], int arrA_size, int arrB[], int arrB_size)</code>.</p> <p>Keep in mind that for function arguments <code>int arrA[]</code> is merely equivalent to <code>int* arrA</code>.</p> <p>As noted by Keith and Sebastian, <code>arrA_size != arrB_size</code> implies different (unless an author of the task defines it in other way). So you check it at the begining and return <code>false</code> if it holds.</p> <p><strong>EDIT</strong></p> <p>Ok, I re-read your post and it seems you need to just display all the not-equal elements and you do not know how to deal with the fact they are of different sizes.</p> <p>Therefore I suggest to start with the following:</p> <pre><code>int compar2arr(int arrA[], int arrA_size, int arrB[], int arrB_size) { int smaller_size = // arrA_size or arrB size, the smaller one; int higher_size = // arrA_size or arrB size, the higher one; int *bigger_array; int i; int result = true; if (arrA_size &gt; arrB_size) bigger_array = arrA; else bigger_array = arrB; for (i = 0; i &lt; smaller_size; i++) { if (/* i-th elements are not(!!) equal */) { result = false; // print the values to be different } } if (smaller_size != higher_size) result = false; for (i = smaller_size; i &lt; higher_size; i++) { // print bigger_array[i] } return result; } </code></pre> <p>I am sure you can come up with the actual code to replace comments. It is not the most concise way to write, but wanted to keep it easy to understand. Anyway, the computational complexity is O(n), the best possible.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload