本文共 673 字,大约阅读时间需要 2 分钟。
今天朋友问我用面向对象实现冒泡排序,说是面试用,写了一个,不知道是否能符合要求,同时希望这个小子能面试成功。
using System;
namespace BubbleSortTest
{
///
/// BubbleSorter 的摘要说明。
///
public class BubbleSorter
{
private int [] _myArray=null;
public int [] MyArray
{
get
{
return _myArray;
}
set
{
_myArray=value;
}
}
public BubbleSorter(int [] myArray)
{
MyArray=myArray;
}
///
/// 排序
///
public void DoSort()
{
for(int i=0;i<_myarray.length-1>
{
int bFlog=0;
for (int j=0;j<_myarray.length-i-1>
{
if(_myArray[j]<_myarray>
{
Swap(ref _myArray[j],ref _myArray[j+1]);
bFlog=1;
}
}
//如果一遍搜索后没有交换说明已经有序,结束排序。
if(bFlog==0)
{
break;
}
}
}
///
/// 传引用交换
///
///
///
public void Swap(ref int i,ref int j)
{
int temp=i;
i=j;
j=temp;
}
}
}
转载地址:https://blog.csdn.net/weixin_32421193/article/details/114593184 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!