拉格朗日差值法, 快速排序.
public static int lagelangri( int [] sz,int num )//拉格朗日排序法.
{
int tou =0; int wei=sz.Length-1; int zhong =0;
while (tou <=wei)
{
zhong = tou + (wei - tou) * (num - sz[tou]) / (sz[wei] - sz[tou]);
if (num == sz [zhong])
{
Console.WriteLine("所查詢的值索引是:{0}",zhong);
break;
}
else if (num >sz[num])
{
tou =zhong+1;
}
else wei=zhong-1;
}
return -1;
}
public static void kuaipai(int [] sz,int left ,int right)//快速排序
{
if (left<right )
{
int i=left;
int j=right-1;
int zhong = sz[(left+right)/2];
while (true)
{
while (i<right &&sz[i]<zhong)
{i++;}
while (j>0&&sz[j]>zhong)
{j--;}
if(i==j )
break;
int num=sz[i];
sz[i]=sz[j];
sz[j]=num;
if (sz[i]== sz[j])
{j--;}
}
kuaipai(sz,left,i);
kuaipai(sz,i+1,right);
}
}