Variablentausch mit/ohne Hilfsvariable

  • Hi,

    was haltet ihr von folgenden Möglichkeiten?

    [autoit]


    dim $a = "1"
    dim $b = "2"

    [/autoit][autoit][/autoit][autoit]

    ;~ tausch1()
    ;~ tausch2()

    [/autoit][autoit][/autoit][autoit]

    func tausch1()
    $a = BitXOR($a, $b)
    $b = BitXOR($a, $b)
    $a = BitXOR($a, $b)
    EndFunc

    [/autoit][autoit][/autoit][autoit]

    func tausch2()
    $tmp = $a
    $a = $b
    $b = $tmp
    EndFunc

    [/autoit][autoit][/autoit][autoit]

    MsgBox(0,"","$a = " & $a & @CRLF & _
    "$b = " & $b)

    [/autoit]

    Im Endeffekt kommt je das gleiche raus, nur eben einmal mit und einmal ohne Hilfsvariable (dementsprechend Auskommentierung entfernen).

    Gruß
    x0r

    Simon nörgelt, Simon nervt - aber Simon verbessert die Welt. Glaubt er.