ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Check for duplicates in array of size 50

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Check for duplicates in array of size 50

    --------------------------------------------------------------------------------

    Any way to check for duplicates in an array apart from looping with each element. if my array size is 50 that is almost 50 * 50 checks if I loop through..

    please help.

    Regards
    Krish
    Thanks N Regards

    Krishnakumar
    !

  • #2
    Re: Check for duplicates in array of size 50

    How about sorta then read through and compare to previous element.
    Won't be 50*50
    Bill
    "A good friend will bail you out of jail,
    A true friend would be sitting beside you saying,
    'Wow, that was fun.'"

    Comment


    • #3
      Re: Check for duplicates in array of size 50

      Well thanks for the idea.. I am checking it out!
      Thanks N Regards

      Krishnakumar
      !

      Comment


      • #4
        Re: Check for duplicates in array of size 50

        Hi rtkriishna:

        Not quite 50 * 50 but that's probably what you had in mind

        Code:
         d     arr         s             20a   dim(6)      
         d     X           s              2S 0             
          /FREE                                            
              arr(1) = 'a';                                
              arr(2) = 'b';                                
              arr(3) = 'c';                                
              arr(4) = 'c';                                
              arr(5) = 'd';                                
              arr(6) = 'e';                                
               FOR X = 1 TO 5;                             
                  IF  %LOOKUP(ARR(X):ARR:(X+1)) <> 0;        
                       DSPLY (ARR(X) + ' ' + %CHAR(X));      
                  ENDIF;                                     
               ENDFOR;                                     
             *inlr=*on;
        The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

        Comment


        • #5
          Re: Check for duplicates in array of size 50

          But that is also similar to 50 * 50 --internally the operation does the same aint it,.,.
          Thanks N Regards

          Krishnakumar
          !

          Comment


          • #6
            Re: Check for duplicates in array of size 50

            Why don't you check for duplicates when you load the array?

            Then, when you load a new array element, you only need to check the array elements that have been loaded thus far to see if its a duplicat.

            ie: if you only have 5 loaded array elements, then before you load the next array element, you can check elements 1 thru 5 to see if its a duplicate.
            Michael Catalani
            IS Director, eCommerce & Web Development
            Acceptance Insurance Corporation
            www.AcceptanceInsurance.com
            www.ProvatoSys.com

            Comment


            • #7
              Re: Check for duplicates in array of size 50

              Hey Michael,

              That was another valid point. Any data received can be validated. I receive the data from front end html page in arrays.
              I validate their duplication by loadinginto another temp array after check with lookup.

              It helped!!

              IT Works!! - Krish
              Thanks N Regards

              Krishnakumar
              !

              Comment

              Working...
              X