📄 bubble2sort.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
namespace GraphicsSort
{
public class Bubble2Sort:SortBase,ISortable
{
public Bubble2Sort(int[] initList, System.Windows.Forms.Control ctlToDraw)
: base("Bubble2Sort",initList, ctlToDraw)
{
}
#region ISortable 成员
public void Sort()
{
IsComplete = false;
SwapCount = 0;
int left = 1;
int right = list.Length - 1;
int tmp;
int t = 0;
int i;
while (left <= right)
{
for (i = right; i >= left; i--)
{
if (list[i] < list[i - 1])
{
tmp = list[i];
list[i] = list[i - 1];
list[i - 1] = tmp;
t = i;
foreach (StepComplete sc in stepComplete.GetInvocationList())
{
sc(ctl, e);
}
SwapCount++;
}
}
left = t + 1;
for (i = left; i <= right; i++)
{
if (list[i] < list[i - 1])
{
tmp = list[i];
list[i] = list[i - 1];
list[i - 1] = tmp;
t = i;
foreach (StepComplete sc in stepComplete.GetInvocationList())
{
sc(ctl, e);
}
SwapCount++;
}
}
right = t - 1;
}
IsComplete = true;
if (sortComplete != null)
{
SortEventArgs e = new SortEventArgs();
e.SwapCount = SwapCount;
e.SortName = SortName;
foreach (SortComplete sc in sortComplete.GetInvocationList())
{
sc(ctl, e);
}
}
}
#endregion
public override event StepComplete stepComplete;
public override event SortComplete sortComplete;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -