By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,513 Members | 1,629 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,513 IT Pros & Developers. It's quick & easy.

finding uncommon elements from 2 array

P: 1
Hi ,
I have two character arrays, I want to get the all the elements from 2nd array which are not in 1st array. Can some one help.



thanks
goldy
May 31 '07 #1
Share this Question
Share on Google+
4 Replies


AdrianH
Expert 100+
P: 1,251
Hi ,
I have two character arrays, I want to get the all the elements from 2nd array which are not in 1st array. Can some one help.



thanks
goldy
We are here to help, but only those who help themselves (by attempting the work). What have you done so far on the problem? What are you having difficulty with?


Adrian
May 31 '07 #2

weaknessforcats
Expert Mod 5K+
P: 9,197
Are you able to write down on a piece of paper the steps you would follow to do this with two arrays that are also written on paper?

Often, you can code from a description. It's kind of a poor man's desiogn specification. Rarely, however, can you code straight out of your head.
May 31 '07 #3

100+
P: 208
A quick and dirty way to do it would be to loop through each of the elements in the 2nd array and check each one with all of the elements in the first array. If none of the elements in the first array matches you know it isn't in there.

Theres definately better way's to do this...
May 31 '07 #4

Expert 10K+
P: 11,448
Hi ,
I have two character arrays, I want to get the all the elements from 2nd array which are not in 1st array. Can some one help.



thanks
goldy
If the two arrays aren't sorted all you can do is check every element in array2
and see if it is present in array1; if it is, skip it, if it isn't store it somewhere.
If you're using C++ you can use a vector or list for that purpose and use some
if its fine functionality; if you're using C you're stuck with arrays and a bit of
memory management.

kind regards,

Jos
May 31 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.