Jump to content

Search the Community

Showing results for tags 'bubblesort'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 1 result

  1. Got Bored, and decided to write up BubbleSort from my early Prelude to Programming class in College. Features: BubbleSorting! Fast on small arrays, extremely slow on larger ones! 2 Dimesional Array Sorting (KINDA)! Sort 2 dimesional arrays! 83 Lines of Code you'll never use because _ArraySort is hundreds faster! #include-once #include <AutoItConstants.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: BubbleSort ; Description ...: Sorts a 1 or 2 dimensional array using the BubbleSort Algorithm ; Syntax ........: BubbleSort($_aArray[, $_bAscending = True]) ; Parameters ....: $_aArray - [in/out] The 1 dimensional array to sort. ; $_bAscending - [optional] Sort by increasing values. Default is True. ; Return values .: Success - Returns 1 ; Failure - Returns 0 and sets @error: ; |1 = Invalid Array, sets @extented: (1, if not a valid array; 2, if not 1 or 2 dimesional) ; |2 = Invalid $_bAscending Flag ; Author ........: Robert C. Maehl (rcmaehl) ; Modified ......: 11/30/2015 ; Remarks .......: To do: Complete Two Dimesional Array sorting ([first,first] = lowest, [last,last] = highest) ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func BubbleSort(ByRef $_aArray, $_bAscending = True) Local $_vReturn = Null Local $_bFinished = False If Not IsArray($_aArray) Then SetError(1,1,0) If UBound($_aArray, $UBOUND_DIMENSIONS) > 2 Then SetError(1,2,0) If Not IsBool($_bAscending) Then SetError(2,0,0) If $_vReturn = Null Then If UBound($_aArray, $UBOUND_DIMENSIONS) = 1 Then While Not $_bFinished $_bFinished = True $_iLoop = 0 $_vTemp = 0 If $_bAscending Then For $_iLoop = 0 To UBound($_aArray) - 2 If $_aArray[$_iLoop] > $_aArray[$_iLoop + 1] Then $_vTemp = $_aArray[$_iLoop] $_aArray[$_iLoop] = $_aArray[$_iLoop + 1] $_aArray[$_iLoop + 1] = $_vTemp $_bFinished = False EndIf Next Else For $_iLoop = 0 To UBound($_aArray) - 2 If $_aArray[$_iLoop] < $_aArray[$_iLoop + 1] Then $_vTemp = $_aArray[$_iLoop] $_aArray[$_iLoop] = $_aArray[$_iLoop + 1] $_aArray[$_iLoop + 1] = $_vTemp $_bFinished = False EndIf Next EndIf WEnd Else ; 2 Dimesional Sorting, Not Yet Complete. (Sort all rows & columns with [0,0] with smallest, and [last,last] with largest) $_iLoop1 = 0 For $_iLoop1 = 0 To UBound($_aArray, $UBOUND_ROWS) - 1 $_bFinished = False While Not $_bFinished $_bFinished = True $_iLoop2 = 0 $_vTemp = 0 If $_bAscending Then For $_iLoop2 = 0 To UBound($_aArray, $UBOUND_COLUMNS) - 2 If $_aArray[$_iLoop1][$_iLoop2] > $_aArray[$_iLoop1][$_iLoop2 + 1] Then $_vTemp = $_aArray[$_iLoop1][$_iLoop2] $_aArray[$_iLoop1][$_iLoop2] = $_aArray[$_iLoop1][$_iLoop2 + 1] $_aArray[$_iLoop1][$_iLoop2 + 1] = $_vTemp $_bFinished = False EndIf Next Else For $_iLoop2 = 0 To UBound($_aArray, $UBOUND_COLUMNS) - 2 If $_aArray[$_iLoop1][$_iLoop2] < $_aArray[$_iLoop1][$_iLoop2 + 1] Then $_vTemp = $_aArray[$_iLoop1][$_iLoop2] $_aArray[$_iLoop1][$_iLoop2] = $_aArray[$_iLoop1][$_iLoop2 + 1] $_aArray[$_iLoop1][$_iLoop2 + 1] = $_vTemp $_bFinished = False EndIf Next EndIf WEnd Next EndIf EndIf EndFunc
×
×
  • Create New...