finding uncommon elements from 2 array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • goldy1980
    New Member
    • May 2007
    • 1

    finding uncommon elements from 2 array

    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
  • AdrianH
    Recognized Expert Top Contributor
    • Feb 2007
    • 1251

    #2
    Originally posted by goldy1980
    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

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      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.

      Comment

      • Silent1Mezzo
        New Member
        • Feb 2007
        • 208

        #4
        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...

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by goldy1980
          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

          Comment

          Working...