Jump to content

Recommended Posts

Posted

As the description says, this has probably already been done before, but i whipped it up for something to do, because of a suggestion i made to someone in the support forum. anyway. you can pass it an unordered array, (with element 0 being the item count) and it removes the duplicates in the array. If this is the same as someone elses, sorry i wasn't trying to rip off ideas, i just didn't check the forums before i did this. If there are others like this, hopefully my sort is faster atleast, making it a little more efficient. let me know what you think...

#include<array.au3>
#cs
    Title:              _ArrayRemoveDupes
    Version:            v1.0
    FileName:           ArrayRemoveDupes.au3
    Description:        Removes duplicate elements from given array.
    Author(s)           CameronsDad - Sean - AIM: SiCKPrLck
#ce
Func _ArrayRemoveDupes($InArray)
    Dim $TempArray[$InArray[0]+1][2]
    $TempArray[0][0] = $InArray[0]
    For $x = 1 to $InArray[0]
        $TempArray[$x][0] = $InArray[$x]
        $TempArray[$x][1] = $x
    Next
Dim $inner,$outer,$temp,$temp2
$n = $temparray[0][0]
$h = 1
While $h <= $n/3
    $h = $h * 3 + 1
WEnd

While $h >0
    For $outer = $h To $n
        $temp = $temparray[$outer][0]
        $temp2 = Number(StringStripWS($temparray[$outer][1],1))
        $inner = $outer
        While $inner > ($h - 1) And StringLower($temparray[$inner-$h][0]) >= StringLower($temp)
            $temparray[$inner][0] = $temparray[$inner-$h][0]
            $temparray[$inner][1] = $temparray[$inner-$h][1]
            $inner = $inner - $h
        WEnd
        $temparray[$inner][0] = $temp
        $temparray[$inner][1] = $temp2
    Next
$h = ($h - 1)/3
WEnd    
For $blah = 1 To $temparray[0][0]-1
    If $TempArray[$blah][0] = $temparray[$blah + 1][0] Then 
        _ArrayDelete($InArray,$temparray[$blah][1])
        $InArray[0] = $InArray[0]-1
    EndIf
Next
Return($InArray)
EndFunc
Posted

I cant get this to work.. can you post an example?

thanks

here ya go.

#include<array.au3>
#cs
    Title:              _ArrayRemoveDupes
    Version:            v1.0
    FileName:           ArrayRemoveDupes.au3
    Description:        Removes duplicate elements from given array.
    Author(s)           CameronsDad - Sean - AIM: SiCKPrLck
#ce

Dim $test1[5]
$test1[0] = 4
$test1[1] = "xray"
$test1[2] = "cat"
$test1[3] = "dog"
$test1[4] = "cat"
_ArrayDisplay($test1,"Input")
$test1 = _ArrayRemoveDupes($test1)
_ArrayDisplay($test1,"Output")
Func _ArrayRemoveDupes($InArray)
    Dim $TempArray[$InArray[0]+1][2]
    $TempArray[0][0] = $InArray[0]
    For $x = 1 to $InArray[0]
        $TempArray[$x][0] = $InArray[$x]
        $TempArray[$x][1] = $x
    Next
Dim $inner,$outer,$temp,$temp2
$n = $temparray[0][0]
$h = 1
While $h <= $n/3
    $h = $h * 3 + 1
WEnd

While $h >0
    For $outer = $h To $n
        $temp = $temparray[$outer][0]
        $temp2 = Number(StringStripWS($temparray[$outer][1],1))
        $inner = $outer
        While $inner > ($h - 1) And StringLower($temparray[$inner-$h][0]) >= StringLower($temp)
            $temparray[$inner][0] = $temparray[$inner-$h][0]
            $temparray[$inner][1] = $temparray[$inner-$h][1]
            $inner = $inner - $h
        WEnd
        $temparray[$inner][0] = $temp
        $temparray[$inner][1] = $temp2
    Next
$h = ($h - 1)/3
WEnd    
For $blah = 1 To $temparray[0][0]-1
    If $TempArray[$blah][0] = $temparray[$blah + 1][0] Then 
        _ArrayDelete($InArray,$temparray[$blah][1])
        $InArray[0] = $InArray[0]-1
    EndIf
Next
Return($InArray)
EndFunc
  • Moderators
Posted

what do you need?

A Double Quarter Pounder with Cheese ... No Pickels, Super Size Fries, and a Large Dr. Pepper Please.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted (edited)

A Double Quarter Pounder with Cheese ... No Pickels, Super Size Fries, and a Large Dr. Pepper Please.

if you didn't want to type all of that you could have just said "the fat bastard special"

***edit***

while i'm confident that you'll take that as the joke that it was intended, let me reinforce that this is just a joke, and i actually even usually order more than that.

Edited by cameronsdad
  • Moderators
Posted

if you didn't want to type all of that you could have just said "the fat bastard special"

***edit***

while i'm confident that you'll take that as the joke that it was intended, let me reinforce that this is just a joke, and i actually even usually order more than that.

:P:lmao::(:):):lmao::king::P

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...