Apex Interview Question - Sort the alphabets without using any of the native collection methods
Let's look at one of the frequently asked interview questions on Apex.
I came across an interview question recently that caught my attention.
The ask is basically we need to sort the alphabets in ascending order without using any of the native collection methods.
I cranked up my dev console and came up with this solution.
I just wanted to put it simple and hence opted for bubble sort algorithm
Hope this helps someone.
let me know if you have a better version of this, more than happy to give you credits and include your solution.
The route that am taking here is
- Create a map of alphabets and assosiate them with serial numbers.
- Take the first element and get it's assosiated number.
- Compare that with the number of every other element of the array.
- If the number assosiasted with the first alphabet is more than the number assosiated with the number of the next alphabet, swap them.