说明: 定义一个10位数的数组,接受穿过来的5 ,就是原数组地1--1共5位 结束,然后取中间值,然后依次循环1.12--4,再去中间值,然后将新拿到的中间值,将原有数组 第5+1 位替换掉,生成一个新数组。 就这样:
1, 1.12, 0.9, 1.2, 1, 4, 1.1, 6, 0.9, 4 原数组
1, 1.12, 0.9, 1.2, 1,1,1.12,1.1,1.2,1.1 新数组
//首次从0开始,数组的首标自动+1;
int zxh = 0;
// 循环完一次后数组的尾标+1
int last = 0;
//List<string> jstring = new List<string>;
List<double> zws = new List<double>();
using (var db = new SecureCloud_Entities())
{
//原数组
double[] myarray = { 1, 1.12, 0.9, 1.2, 1, 4, 1.1, 6, 0.9, 4 };
double[] newmyarray = new double[myarray.Length];
myarray.CopyTo(newmyarray,0);
int length = myarray.Length;
int a = 5; //传过来的值,到第几位结束
//最终循环次数
int cycles = length - a;
List<double> windowPixelColorList = new List<double>();
double med;
// int zzxh = length - a + 1;
for (int i = zxh; i <= myarray.Length; i++)
{
if (zxh < cycles)
{
if (i <= a - 1 + last) // &&
{
windowPixelColorList.Add(myarray[i]);
windowPixelColorList.Sort();
//数组从0开始,满足6时进入取中位数
if (a - i + last == 1)
{
i = zxh;
double[] list = windowPixelColorList.ToArray();
int count = list.Length;
//判断中位数是偶数
if (count % 2 == 0)
{
med = (list[count / 2] + list[count / 2 - 1]) / 2d;
}
else
{
//中位数奇数
med = list[count / 2];
}
//
newmyarray[a + last] = med;
zws.Add(med);
zxh++;
windowPixelColorList = new List<double>();
last++;
}
}
}
else
{
break;
}
}
Console.WriteLine(" {0}", zws.ToString()); //原来的数据
Console.WriteLine(" {0}", newmyarray.ToString()); //改变后的数据
}
return ;