DEV Community

Cover image for [Golang] Sorting String In Alphabetical Order
Kuldeep Singh
Kuldeep Singh

Posted on

5 1

[Golang] Sorting 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 number 97.

We have covered all reading part which was important while we were going to code, So let's start writing code.

func alphasort(str []rune, depth int) {
    for x := range str {
        y := x + 1
        for y = range str {
            if str[x] < str[y] {
                str[x], str[y] = str[y], str[x]
            }
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Checkout Here for more methods on bubble sort implementation:
https://kdsingh4.blogspot.com/2021/10/golang-sort-string-in-alphabetical-order.html

Checkout More Algorithms Solutions: https://kdsingh4.blogspot.com/search/label/algorithm?&max-results=5/feed/

Don't Forget To Subscribe My Youtube Channel as well:
https://www.youtube.com/channel/UCXhmNqWQ50zitqIdTgS7s8Q

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo 📊✨

Top comments (0)

Image of Stellar post

🚀 Stellar Dev Diaries Series: Episode 1 is LIVE!

Ever wondered what it takes to build a web3 startup from scratch? In the Stellar Dev Diaries series, we follow the journey of a team of developers building on the Stellar Network as they go from hackathon win to getting funded and launching on mainnet.

Read more

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, cherished by the supportive DEV Community. Coders of every background are encouraged to bring their perspectives and bolster our collective wisdom.

A sincere “thank you” often brightens someone’s day—share yours in the comments below!

On DEV, the act of sharing knowledge eases our journey and forges stronger community ties. Found value in this? A quick thank-you to the author can make a world of difference.

Okay