Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are several commonly used C# sorting methods?

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

What are several commonly used C# sorting methods? I believe that many inexperienced people are at a loss about this. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

These five C# sorting methods are actually common in other language platforms, so C# sorting methods can also be said to be sorting methods in other languages, but they are implemented in different languages.

See many classical sorting methods on the Internet, the algorithm is divided into:

1: insert sort a. Directly insert sort b. Hill ranking

2: exchange sort a. Bubble sort b. Quick sort

3: select sort a. Direct selection sort

4: merge sort a. Merge and sort

5: allocation sort a. Box sort b. Cardinality sort

I commonly used three kinds of C # sorting methods: 1. Direct selection sort 2. Directly insert sort 3. Bubble sort; let me explain it in C # language.

The first kind: bubble sorting

Principle: for a series of numbers, we will cycle and exchange it, each time the number or the minimum number will be put at the end of the opposite end, and the cycle will be carried out in turn, and the length of the cycle is-1.

Public class EbullitionSorter {public void Sort (int [] arr) {for (int ionomarr.arr [I] = temp;} {for (if [I] {int temp=arr [I]; arr [I] = arr [j])}

The second kind: selective sorting

Principle: for a sequence, we choose * or the smallest number, put it at the end of the line, cycle down in turn, and the cycle length is-1; because there is no bubbling sort, it is faster than bubbling sort.

Public class SelectionSorter {private int min; public void Sort (int [] arr) {for (int iTuno Tipi {min=i; for (int juniifol1 min=j; j {if (arr [j] {min=j;}} int temp=arr [min]; arr [min] = ARR [I]; arr [I] = temp;})

The third kind: insert sort

Principle: for a series of numbers, we start with the second number, compare it with the number in front of it, and select * each time.

Or the smallest number is placed at the head of the queue, thus forming an orderly queue, so it is faster than selecting.

Public class InsertionSorter {public void Sort (int [] arr) {for (int item1 Ting I {int temp=arr [I]; int Jaimi; while ((j > 0) & & (arr (jmur1) > temp)) {arr [j] = arr [j-1];-- j;} arr [j] = temp;}

The above three methods are commonly used by myself, which are very simple and easy to understand, which are very helpful to beginners.

Many people have learned the idea of object-oriented and write down how to sort objects next time.

After reading the above, do you know what the commonly used C# sorting methods are? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report