VerseIsland
FeedLearnLeaderboardGuidesReferenceExploreSearchDocsVerse Library
Sign in
Feed Learn 📖 Codex Leaderboard Guides Reference Explore Search Docs Verse Library
Browse Community Snippets›Verse Language·Up to Community Snippets · Verse Language·114 of 114 in Verse Language

Bubble Sort

64,596 Views

Report

  • # A simple sorting algorithm that steps through the array element by element,
    # comparing and swapping two elements if they're not in order.
    # When no swaps are done, then the list is sorted.
    BubbleSort<public>(Array:[]t, Compare(L:t, R:t)<decides><transacts>:t where t:subtype(comparable))<transacts>:[]t=
        Length:int = Array.Length
        var OrderedArray:[]t = Array
    
        # Iterate through the whole array.
        for:
            FirstIndex := 0..Length - 1
        do:
            # Tracking if any swaps were performed.
            var DidSwap:logic = false
    
            # Go element by element and compare adjacent elements.
            # Largest elements will "bubble up" to the end first,
            # so can ignore as many elements at the end as we've already checked.
            for:
                SecondIndex := 0..Length - FirstIndex - 1
                not Compare[OrderedArray[SecondIndex], OrderedArray[SecondIndex + 1]]
                ArrayWithSwappedElements := OrderedArray.Swap[SecondIndex, SecondIndex + 1]
            do:
                set OrderedArray = ArrayWithSwappedElements
                set DidSwap = true

You're reading a preview

The full reference is free for BrainDeadGuild Discord members — sign in to read it all, or open the original at the source.

Sign in with Discord — free for members Read the original at Epic Games documentation

Sign in with your BrainDead.TV / BrainDeadGuild Discord account for full access.

Guided course

Add this to your free study plan — we’ll suggest related material and stitch it into one compile-checked lesson.

Keep exploring
More in Verse Language · 114 of 114
Prev
fortnite selective scoring system version 1

Source

Epic Games documentation

View original

Last updated 2026-07-26T12:03:11.911508+00:00

VerseIsland· an archipelago of Verse & UEFN knowledge
🗺️ Island atlasLearnGuidesHistoryAbout & PressSources & LicensingPrivacy PolicyTermsStatus

Not affiliated with Epic Games. Fortnite, UEFN, Unreal Engine, and Verse are trademarks of Epic Games, Inc. Content is attributed to its source — see Sources & Licensing.

🦜

Scout · your island guide

The Isle of Verse