onSorter
{
private int min;
public void Sort(int[] arr)
{
for (int i = 0; i < arr.Length - 1; ++i)
{
min = i;
for (int j = i + 1; j < arr.Length; ++j)
{
if (arr[j] < arr[min])
min = j;
}
int t = arr[min];
arr[min] = arr[i];
arr[i] = t;
}
}
static void Main(string[] args)
{
int[] array = new int[] ;
SelectionSorter s = new SelectionSorter();
s.Sort(array);
foreach (int m in array)
Console.WriteLine("", m);
}
}
//冒泡排序
class EbullitionSorter
{
public void Sort(int[] arr)
{
int i, j, temp;
bool done = false;
j = 1;
while ((j < arr.Length) && (!done))//判断长度
{
done = true;
for (i = 0; i < arr.Length - j; i++)
{
if (arr[i] > arr[i + 1])
{
done = false;
temp = arr[i];
arr[i] = arr[i + 1];//交换数据
arr[i + 1] = temp;
}
}
j++;
}
}
static void Main(string[] args)
{
int[] array = new int[] ;
EbullitionSorter e = new EbullitionSorter ();
e.Sort(array);
foreach (int m in array)
Console.WriteLine("", m);
}
}
//快速排序
class QuickSorter
{
private void swap(ref int l, ref int r)
{
int temp;
temp = l;
l = r;
r = temp;
}
public void Sort(int[] list, int low, int high)
{
int pivot;//存储分支点
int l, r;
int mid;
if (high <= low)
return;
else if (high == low + 1)
{
if (list[low] > list[high])
swap(ref list[low], ref list[high]);
return;
}
mid = (low + high) >> 1;
pivot = list[mid];
swap(ref list[low], ref list[mid]);
l = low + 1;
r = high;
do
{
while (l <= r && list[l] < pivot)
l++;
while (list[r] >= pivot)
r--;
if (l < r)
swap(ref list[l], ref list[r]);
} while (l < r);
list[low] = list[r];
list[r] = pivot;
if (low + 1 < r)
Sort(list, low, r - 1);
if (r + 1 < high)
Sort(list, r + 1, high);
}
static void Main(string[] args)
{
int[] iArrary = new int[] ;
QuickSorter q = new QuickSorter();
q.Sort(iArrary, 0, 13);
for (int m = 0; m <= 13; m++)
Console.WriteLine("", iArrary[m]);
}
}
//插入排序
public class InsertionSorter
{
public void Sort(int[] arr)
{
for (int i = 1; i < arr.Length; i++)
{
int t = arr[i];
int j = i;
while ((j > 0) && (arr[j - 1] > t))
{
arr[j] = arr[j - 1];//交换顺序
--j;
}
arr[j] = t;
}
}
static void Main(string[] args)
{
int[] array = new int[] ;
InsertionSorter i = new InsertionSorter();
i.Sort(array);
foreach (int m in array)
Console.WriteLine("", m);
}
}
//希尔排序
public class ShellSorter
{
public void Sort(int[] arr)
{
int inc;
for (inc = 1; inc <= arr.Length / 9; inc = 3 * inc + 1) ;
for (; inc > 0; inc /= 3)
{
for (int i = inc + 1; i <= arr.Length; i += inc)
{
int t = arr[i - 1];
int j = i;
while ((j > inc) && (arr[j - inc - 1] > t))
{
arr[j - 1] = arr[j - inc - 1];//交换数据
j -= inc;
}
arr[j - 1] = t;
}
}
}
static void Main(string[] args)
{
int[] array = new int[] ;
ShellSorter s = new ShellSorter();
s.Sort(array);
foreach (int m in array)
Console.WriteLine("", m);
}
}
看你要什么排序吧~都可以直接运行
另外,团IDC网上有许多产品团购,便宜有口碑
#include
using namespace std;
int Shun_zi(int a[],int nLen); //我自己写的顺子函数。你看看
int sort(int m[],int nLen); //扑克牌数排序
int print(int b[],int nLen); //输出全部扑克牌数
int canf(int n[],int nLen); //输入扑克牌数
int judge(int x[],int nLen); //判定输入的扑克牌数是否合理
int Csame(int a[],int start,int result) ; //输出大于5个数的顺子
//int merger(int a[],int nLen); //没有必要。已删除。
int Start=0;
int main()
{
int y[10]={6,5,3,4,3,8,4,8,9,2};
cout<<"请输入10个数"<
cout<<"输入的数字为"<
judge(y,10); //判断是否为扑克牌数
sort(y,10); //从小到大排序
cout<<"排序后的数为"<
if(Shun_zi(y,10)<5)
{
cout<<"没有顺子"<
else
{
Csame(y,Start,Shun_zi(y,10));
}
cout<
}
int Shun_zi(int a[],int nlen)
{
if(nlen==0)return 0;
if(nlen==1)return 1;
int tmp=0,result=0,start=0,cur=0;
for(int i=1;i
if(a[i]==a[i-1]+1)
{
tmp++;
}
else
{
if(a[i]==a[i-1])
{
continue;
}
else
{
if(tmp>result)
{
start=cur;
result=tmp;
}
tmp=0;
cur=i;
}
}
}
Start=start;
return result+1;
}
int Csame(int a[],int start,int result)
{
if(a==NULL)
{
return 0;
}
if (result>4)
{
cout< for (int i=1;i
if(a[start+i]!=a[start+i-1])
cout< else
{
result++;//遇到重复往前终点移动一些
}
}
cout<
return 0;
}
int sort(int m[],int nLen)
{
if(m == NULL)
{
return 0;
}
if (nLen==0)
{
return 0;
}
int i=0;
int j=0;
int temp=0;
for (i=0;i
for(j=i+1;j
if (m[i]>m[j])
{
temp=m[i];
m[i]=m[j];
m[j]=temp;
}
}
}
return 0;
}
int print(int b[],int nLen)
{
if(b == NULL)
{
return 0;
}
if (nLen==0)
{
return 0;
}
int i=0;
for(i=0;i
cout< }
cout<
}
int canf(int n[],int nLen)
{
for(int i=0;i
cin>>n[i];
}
return 0;
}
int judge(int x[],int nLen)
{
if(x == NULL)
{
return 0;
}
if (nLen==0)
{
return 0;
}
int max=0;
int min=0;
int k=0;
for (k=0;k
if (max
max=x[k];
}
if (min>x[k])
{
min=x[k];
}
}
if (max-min>13)
{
cout<<"不是扑克牌数"<
else
{
cout<<"是扑克牌数"<
}
return 0;
}
vc6.0上可以跑,没有错。。。