TwiceIn2DArray

« Older   Newer »
  Share  
LoGiX
CAT_IMG Posted on 4/2/2012, 22:10     +1   +1   -1




Hello,
Ho create questa funzione che controlla se in un array (bidimensionale) č presente un elemento duplicato.
Se lo trova, ritorna l'index dell'elemento (duplicato) oppure True, in base al parametro flag.
(Trovate tutte le spiegazioni all'interno del codice :asd:)

Esempio:
Dim $array[4][2] = [ [12,13], [14,25], [13,1], [12,13] ]

Sia [n][0] che [n][1] devono essere uguali (anche come posizione) a quelli trovati la prima volta.

Ecco il codice (+ esempio)
CODICE
#include <array.au3>

Dim $array[3][2] = [ [12,12], [12,13], [12,12] ]

MsgBox(0,"","Index: "&TwiceIn2DArray($array)&@CRLF&"@error: "&@error)


#cs
       Se flag = 0:
               ritorna True o False
       Se flag = 1:
               ritorna l'index dell'elemento trovato e @error = 0
               ritorna -1 e @error = 1
       Se flag non č valido:
               ritorna -1 e @error = 2
#ce
Func TwiceIn2DArray($array,$flag = 1)
       Dim $array2 [1][2]
       Local $i

       If $flag <> 0 And $flag <> 1 Then
               Return SetError(2, 0, -1)
       EndIf

       $len = UBound($array)-1
       For $i = 0 To $len
               If _ArraySearch($array2,$array[$i][0],0,0,0,0,1,0) <> -1 And _ArraySearch($array2,$array[$i][1],0,0,0,0,1,1) <> -1 Then
                       If $flag = 0 Then
                               Return SetError(0, 0, True)
                       ElseIf $flag = 1 Then
                               Return SetError(0, 0, $i)
                       EndIf
               Else
                       ReDim $array2[UBound($array2)+1][2]
                       $array2[UBound($array2)-1][0] = $array[$i][0]
                       $array2[UBound($array2)-1][1] = $array[$i][1]
               EndIf
       Next

       If $flag = 0 Then
               Return False
       ElseIf $flag = 1 Then
               Return SetError(0,0,-1)
       EndIf

EndFunc


NB: Serve l'include <array.au3>

Edited by LoGiX - 5/2/2012, 02:49
 
Top
I.Ren
CAT_IMG Posted on 4/2/2012, 23:55     -1   +1   -1




utile : D consiglio, al posto di ritornare true fai che ritorni l'elemento duplicato e magari anche la sua posizione nell'array
 
Top
LoGiX
CAT_IMG Posted on 5/2/2012, 02:50     -1   +1   -1




CITAZIONE (I.Ren @ 4/2/2012, 23:55) 
utile : D consiglio, al posto di ritornare true fai che ritorni l'elemento duplicato e magari anche la sua posizione nell'array

Fatto :asd:
 
Top
I.Ren
CAT_IMG Posted on 5/2/2012, 12:10     -1   +1   -1




ottimo : D
 
Top
»Master
CAT_IMG Posted on 6/2/2012, 16:55     +1   -1




bravo xD
anche se a me non mi piace la udf array.au3 xd
 
Top
FrontBack
CAT_IMG Posted on 6/2/2012, 20:35     +1   +1   -1




CITAZIONE (»Master @ 6/2/2012, 16:55) 
bravo xD
anche se a me non mi piace la udf array.au3 xd

ma a te non piace 'na beata minchia delle udf che ci sono :lool:
 
Top
»Master
CAT_IMG Posted on 7/2/2012, 02:09     +1   -1




veramente a me non piace nessuna libreria che non usi qualche API o libreria esterna xD
 
Top
bradipooso
CAT_IMG Posted on 7/2/2012, 09:24     +1   -1




CITAZIONE (»Master @ 6/2/2012, 16:55) 
anche se a me non mi piace la udf array.au3 xd

:hmm: ?




 
Top
7 replies since 4/2/2012, 22:10   108 views
  Share