Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: JavaHomework
how do i compare characters of two arrays before adding elements from one of the arrays into the other, inorder to ensure that if the characters already exist in the destination array, then that character should not be copied into it?
Posted 19-Nov-12 4:41am
Edited 19-Nov-12 22:05pm
Nelek at 19-Nov-12 11:21am
What type of data are you actually speaking about? How about the length of the arrays / volumen of data?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

As far as the arrays are not too long and that the type of data can be compared with == operator
You can use two for loops one nested into the another one. Actually the same operation than going through a 2-dimensional array[i][j]
bool error = false;
for (int i=0; i < length_a; i++)
   for (int j=0; j < length_b; j++)
      if (array_a[i]== array[b] array_b[j])
         error = true;
if (error == false)
   // No match found, do whatever you need to
[edit] array[b] corrected to array_b[j] [/edit]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
0 Sergey Alexandrovich Kryukov 355
1 Abhinav S 333
2 sanket saxena 305
3 CPallini 205
4 thatraja 195
0 Sergey Alexandrovich Kryukov 8,497
1 OriginalGriff 4,850
2 Peter Leow 3,839
3 Maciej Los 3,535
4 Er. Puneet Goel 3,107

Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid