[Golang] Sort String In Alphabetical Order
In this article we are going to learn about how we can sort strings in golang the order we are going to implement is ascending order. If you are not familiar what ascending and descending order is let me explain you about it or if you knows then you can skip that part.
What is Ascending Order?
Ascending order is a method of arranging numbers from smallest value to largest value. The order goes from left to right. Ascending order is also sometimes named as increasing order. For example, a set of natural numbers are in ascending order, such as 1, 2, 3, 4, 5, 6, 7, 8… and same for the alphabets as well. The inverse method of increasing order is descending order, where the numbers are arranged in decreasing order of values.
What is Descending Order?
If the information is sorted from highest to lowest, it is said to be in descending order. For example 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 are arranged in descending order. In other words, if the numbers are arranged from the largest to the smallest number, it is said to be in descending order.
In simple words, descending order is defined as an arrangement in the highest to lowest format. These concepts are related to decimals, numbers, fractions or amount of money.
Example of Descending Order
24, 20, 18, 12, 7 are arranged in descending order.
This is also known as decreasing order of numbers.
So now we knows what is ascending and descending order then let's move forward main part which is runes.
What is Rune in Golang?
Rune literals are just 32-bit integer values (however they're untyped constants, so their type can change). They represent unicode codepoints. For example, the rune literal'a'
is actually the number97
.
We have covered all reading part which was important while we were going to code, So let's start writing code.
1. Converting String To Slice of Rune
2. Sorting The Rune Values
In alphasort function we are using bubble sort and sorting the slice of rune via numbers because we can't directly compare characters which is bigger or not.
0 Comments:
Post a Comment
If have any queries lemme know
Subscribe to Post Comments [Atom]
<< Home