Bubble sort in C/AL

Naresh Vaneshwar
Nareshwar R.
Published in
1 min readMar 1, 2016

Sorting.. Yes, I could have used Record.SETCURRENTKEY() if I am retrieving values from a table. But I had to sort some decimal/integer variables which I used while running a report.
I was thinking what if I use one of the old school sorting algorithms, and then I decided to implement Bubble Sort in C/AL. You may argue that the complexity of a Bubble Sort is meh.. but personally, I like this algorithm because it is quite easy to implement.

Here is the code.

rankArray’s dimension = 10.

Here are the results.

Before Sorting: 25,24,30,28,39,27,22,25,34,35
After Sorting: 22,24,25,25,27,28,30,34,35,39

--

--

Naresh Vaneshwar
Nareshwar R.

Technical findings and new developments on Business Central