1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
int compare (int cloneArray[], int parallelArray[], int i, int j)
{
if (cloneArray[i] == parallelArray[j])
return 1; ///true
else
return 0; ///false
}
int main()
{
int repeat = 0;
int vectorlength = 5;
int array1[5] = {2,2,2,2,2};
int array2[6] ;
int j = 0, result;
for (int w =0 ; w < vectorlength; w++)
{
cout <<"W: "<<w<<endl;
j = 0; ///Index variable in parrallel array which begins empty
///its always going to be reset to 0 to start comparing from the beginning when getting the next w.
while (w <= j) ///While i havent reached the las occupied row in parallel array(array2)
{
result = compare(array1, array2, w, j ); ///always start comparing from current i up to J
//cout <<endl<<"J is:"<<j<<endl;
cout << "compare(w) "<<w<<" & "<<"(j)"<<j<<endl;
cout <<"res: "<<result<<endl<<endl;
if (result == 1 ) ///if there is match, increase repeat, then check();
{
cout <<"YESSSS->match ";
cout <<"array1["<<w<<"] to array2["<<j<<"] "<<endl;
repeat++;
//**Check();
break;
}
if ( (result == 0 )&& ( w == j) ) ///After having compared up to the las occupied row(j)
{
cout << "no match from array1["<<w<<"] up to "<< j<<endl;
cout << "copying array1["<<w<<"] to "<<"array2["<<j+1<<"] "<<endl; ///Put that unique number in next avail slot j+1
array2[j+1] = array1[w]; ///
j++;
break;
}
cout<<"NO MATCH UPTO J:"<<j<<" compare to next j"<<endl;
j++; ///If neither of the two previous if were met, continue comparing my current array1[i] to next array2[j++];
}
}
return 0;
}
|