What's the most elegant way to bubble-sort in C#?

后端 未结 10 1866
旧巷少年郎
旧巷少年郎 2020-12-06 03:33

Can this be cleaned up?

using System;  
class AscendingBubbleSort 
{     
    public static void Main()
    {
        int i = 0,j = 0,t = 0;
        int []c=         


        
10条回答
  •  萌比男神i
    2020-12-06 03:55

    • I would use a swap methed to swap the two array items. (details of how to write swap method left as homework!)

    • You should think about the case when the items are already in order

    • You should read up on Insertion sort for more marks :-)

    • Rather then reading the test data from the keyboard, see if you can learn how to use nUnit

提交回复
热议问题