Proton BASIC Compiler - BubbleSort


  • PicŪ Basic


  • BubbleSort

    A library module for use withLibrary Manager by JohnGB. This module has been written by Tim Box (Tim on PDS forum). The library module is offered on an as-is basis with no warranty as to its effectiveness, operation or reliability. Users use it at their own risk.

    Adds a new command called BubbleSort

    Syntax

    BubbleSort Array, Elements, Direction

    Overview

    Performs a bubble sort on N number of elements on a byte array in either direction.

    Operators

    Array – any Byte array

    Elements - a constant, or byte variable indicating the number of elements within the array to sort

    Direction - a constant, or byte variable indicating the direction of sorting 0 or 1. Any number > 0 will be taken as 1. 1 = high numbers first, 0 = low numbers first

    Code:
    Include "proton_4.inc""   
    
        Dim myarray[10] As Byte
        Dim index As Byte
    
        For index = 0 To 9
            myarray[index] = index
            HRSOut Dec myarray[index],", "
        Next
    
        HRSOut 13,10 
    
        index = 1 
    
        BubbleSort myarray, 10, index
    
        For index = 0 To 9
            HRSOut Dec myarray[index],", "
        Next
    
        HRSOut 13,10
    
        index = 10
    
        BubbleSort myarray, index, 0 
    
        For index = 0 To 9
            HRSOut Dec myarray[index],", "
        Next
    
        HRSOut 13,10
    
        Stop
    The above example code will fill an array with the values from 0 to 9 and send then sort the array first down then up.


    Download module

    Download: Bubble Sort
  • Recent Activity

    keytapper-79800

    The Proton manual

    Thread Starter: towlerg

    I don't know if it's just me but I don't seem to be able to paste examples from the PDF. I'm sure I could at some time in the past but maybe I'm...

    keytapper Today, 15:37 Go to last post
    flosigud-23425

    SD File System revisited

    Thread Starter: AlbertoFS

    I have reviewed the SD_File_System in a file.inc only checking all macros using the preprocessor too. I have tried to make the commands easier to...

    flosigud Today, 16:41 Go to last post