using
System;
using System.Collections.Generic;
using System.Text;
namespace bleb_sort
{
class Program
{
public class SwapObj
{
public static void swap < T > ( ref Ta, ref Tb)
{
Tc;
c = a;
a = b;
b = c;
}
}
static void Main( string []args)
{
// 冒泡排序:
int []num = new int [] { 12 , 3 , 6 , 16 , 19 , 7 , 33 , 21 , 20 , 100 , 100 , 115 , 55 , 58 , 77 } ;
foreach ( int i in num)
{
Console.Write(i.ToString() + " , " );
}
Console.WriteLine();
Console.WriteLine( " 排序后: " );
int counter1 = 0 ;
int counter2 = 0 ;
for ( int i = 0 ;i < num.Length - 1 ;i ++ )
{
for ( int j = i + 1 ;j < num.Length;j ++ )
{
if (num[i] < num[j])
{
SwapObj.swap < int > ( ref num[i], ref num[j]);
counter1 ++ ;
}
counter2 ++ ;
}
}
Console.WriteLine( " 循环了{0}次。 " ,counter2);
Console.WriteLine( " 其中交换了{0}次。 " ,counter1);
foreach ( int i in num)
{
Console.Write(i.ToString() + " , " );
}
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Text;
namespace bleb_sort
{
class Program
{
public class SwapObj
{
public static void swap < T > ( ref Ta, ref Tb)
{
Tc;
c = a;
a = b;
b = c;
}
}
static void Main( string []args)
{
// 冒泡排序:
int []num = new int [] { 12 , 3 , 6 , 16 , 19 , 7 , 33 , 21 , 20 , 100 , 100 , 115 , 55 , 58 , 77 } ;
foreach ( int i in num)
{
Console.Write(i.ToString() + " , " );
}
Console.WriteLine();
Console.WriteLine( " 排序后: " );
int counter1 = 0 ;
int counter2 = 0 ;
for ( int i = 0 ;i < num.Length - 1 ;i ++ )
{
for ( int j = i + 1 ;j < num.Length;j ++ )
{
if (num[i] < num[j])
{
SwapObj.swap < int > ( ref num[i], ref num[j]);
counter1 ++ ;
}
counter2 ++ ;
}
}
Console.WriteLine( " 循环了{0}次。 " ,counter2);
Console.WriteLine( " 其中交换了{0}次。 " ,counter1);
foreach ( int i in num)
{
Console.Write(i.ToString() + " , " );
}
Console.ReadLine();
}
}
}