Get the App
SLTechnology News&Howtos  ›  Development  › 

How to develop sorting calculation in C #

Shulou Source: shulou.com Published: 2022-06-02 09:02:36 10月30日 Update

This article mainly shows you "how to develop sorting calculation in C#". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn the article "how to develop sorting calculation in C#".

Bubbling sort

Learning a language takes a lot of effort to learn data structures and algorithms.

Using System; namespace BubbleSorter {public class BubbleSorter {public void Sort (int [] list) {int iReporter jtemp; bool done=false; job1; while ((j < list.Length) & & (! done)) {done=true; for (iLife0 done < list.Length-j;i++) {if (list [I] > list [I]) {done=false; temp=list [I]; list [I] = list [I + 1]; list [I] = temp;}} junk + } public class MainClass {public static void Main () {int [] iArrary=new int [] {1 int 5 iArrary.Length;m++ 13, 6, 10, 99 99, 87, 12, 34, 75, 47); BubbleSorter sh=new BubbleSorter (); sh.Sort (iArrary); for (int massively 0 iArrary.Length;m++) Console.Write ("{0}", iArrary [m]); Console.WriteLine ();}

Select sort

I use C # to develop sorting algorithm. I hope it can bring some benefits to the learners of C # language. Don't forget that learning a language takes a lot of effort to learn data structures and algorithms.

Using System; namespace SelectionSorter {public class SelectionSorter {private int min; public void Sort (int [] list) {for (int item0 political I < list.Length-1;i++) {min=i; for (int jimmin1 int j < list.Length;j++) {if (list [j] < int [min]) min=j;} int t=list [min]; list [min] = list [I]; list [I] = t } public class MainClass {public static void Main () {int [] iArrary=new int [] {1pje 5pje 3pje 6je 105pas 55g 9pr 2pr 2pr 87pr 34pr 73pct 47}; SelectionSorter ss=new SelectionSorter (); ss.Sort (iArrary); for (int mendacious m < iArrary.Length;m++) Console.Write ("{0}", iArrary [m]); Console.WriteLine ();}

Insert sort

Insert sorting algorithm. For those who want to improve their programming ability in C # language, we can discuss it with each other. Such as: the following program, does not achieve polymorphism, come, help it to achieve.

Using System; namespace InsertionSorter {public class InsertionSorter {public void Sort (int [] list) {for (int item1 politics I < list.Length;i++) {int t=list [I]; int junii; while ((j > 0) & & (list [j-1] > t)) {list [j] = list [j-1];-- j;} list [j] = t } public class MainClass {public static void Main () {int [] iArrary=new int [] {1, 13, 5, 10, 5, 9, 8, 8, 8, 8, 12, 4, 4, 3, 3, 4, 7, 4, 3, 4, 3, 7, 47, 7, 12, 4, 4, 3, 7, 47, int (), ii.Sort (iArrary), for (int mendaci, iArrary.Length;m++) Console.Write ("{0}", iArrary [m]); Console.WriteLine ();}

Hill ranking

Hill sort is to segment the group and sort it by insertion. For those who want to improve their programming ability in C # language, we can discuss it with each other. Such as: the following program, does not achieve polymorphism, come, help it to achieve.

Using System; namespace ShellSorter {public class ShellSorter {public void Sort (int [] list) {int inc; for (inc=1;inc < = list.Length/9;inc=3*inc+1); for (; inc > 0 incincposure 3) {for (int iteminception inception I < = list.Length;i+=inc) {int t = list [I-1]; int jambii; while ((j > inc) & & (list [j-inc-1] > t)) {[j-1] = list [j-inc-1] [J-1] = t;} public class MainClass {public static void Main () {int [] iArrary=new int [] {1, 513, 6, 10, 99, 8, 12, 4, 3, 47, ShellSorter sh=new ShellSorter (); sh.Sort (iArrary); for (int massively 0tm < iArrary.Length;m++) Console.Write ("{0}", iArrary [m]); Console.WriteLine () } these are all the contents of the article "how to develop sorting calculation in C#". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Sorting programming algorithms content articles languages learning polymorphism strength data data structures friends programs structures capabilities language programming face-to-face language learning Hill Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Microsoft Shulou Tech Info MySQL Redmi