C#,数值计算——索引类(Index)的计算方法与源程序

using System;

namespace Legalsoft.Truffer

{

public class Indexx

{

public int n { get; set; } = 0;

public int\[\] indx;

public Indexx()

{

}

public Indexx(double\[\] arr)

{

index(arr, arr.Length);

}

public void sort(double\[\] brr)

{

if (brr.Length != n)

{

throw new Exception("bad size in Index sort");

}

double\[\] tmp = Globals.CopyFrom(brr);

for (int j = 0; j < n; j++)

{

brrj = tmpindx\[j];

}

}

public void sort(int\[\] brr)

{

if (brr.Length != n)

{

throw new Exception("bad size in Index sort");

}

int\[\] tmp = Globals.CopyFrom(brr);

for (int j = 0; j < n; j++)

{

brrj = tmpindx\[j];

}

}

public double el(double\[\] brr, int j)

{

return brrindx\[j];

}

public int el(int\[\] brr, int j)

{

return brrindx\[j];

}

public void setEl(int\[\] brr, int j, int v)

{

brrindx\[j] = v;

}

public void setEl(double\[\] brr, int j, double v)

{

brrindx\[j] = v;

}

public void rank(int\[\] irank)

{

irank = new intn;

for (int j = 0; j < n; j++)

{

irankindx\[j] = j;

}

}

public void index(double\[\] arr, int nn)

{

const int M = 7;

const int NSTACK = 64;

int jstack = -1;

int\[\] istack = new intNSTACK;

n = nn;

indx = new intn;

int ir = n - 1;

for (int j = 0; j < n; j++)

{

indxj = j;

}

int l = 0;

for (; ; )

{

if (ir - l < M)

{

for (int j = l + 1; j <= ir; j++)

{

int indxt = indxj;

double a = arrindxt;

int i = j - 1;

for (; i >= l; i--)

{

if (arrindx\[i] <= a)

{

break;

}

indxi + 1 = indxi;

}

indxi + 1 = indxt;

}

if (jstack < 0)

{

break;

}

ir = istackjstack--;

l = istackjstack--;

}

else

{

int k = (l + ir) >> 1;

Globals.SWAP(ref indxk, ref indxl + 1);

if (arrindx\[l] > arrindx\[ir])

{

Globals.SWAP(ref indxl, ref indxir);

}

if (arrindx\[l + 1] > arrindx\[ir])

{

Globals.SWAP(ref indxl + 1, ref indxir);

}

if (arrindx\[l] > arrindx\[l + 1])

{

Globals.SWAP(ref indxl, ref indxl + 1);

}

int i = l + 1;

int j = ir;

int indxt = indxl + 1;

double a = arrindxt;

for (; ; )

{

do

{

i++;

} while (arrindx\[i] < a);

do

{

j--;

} while (arrindx\[j] > a);

if (j < i)

{

break;

}

Globals.SWAP(ref indxi, ref indxj);

}

indxl + 1 = indxj;

indxj = indxt;

jstack += 2;

if (jstack >= NSTACK)

{

throw new Exception("NSTACK too small in index.");

}

if (ir - i + 1 >= j - l)

{

istackjstack = ir;

istackjstack - 1 = i;

ir = j - 1;

}

else

{

istackjstack = j - 1;

istackjstack - 1 = l;

l = i;

}

}

}

}

}

}

相关推荐
_清歌10 小时前
DSpark 深度解读:DeepSeek-V4 如何用「半自回归」把推理速度提升 85%
算法
统计实现局10 小时前
SVD 的三步走:双对角化、Givens 收敛、排序
算法
躬行见万象10 小时前
《VLA 系列》UniLab 强化训练 | G1 机器人 |复现
算法
统计实现局10 小时前
对称不定分解(Bunch-Kaufman):为什么 Cholesky 不够用
算法
统计实现局10 小时前
dqrsl 拆解:拿着 QR 结果能算出哪 5 种东西
算法
统计实现局10 小时前
为什么 Cholesky 求逆比 Gauss-Jordan 快一倍——行列式溢出防护详
算法
To_OC1 天前
LC 994 腐烂的橘子:人人都说是 BFS 入门题,我却写了三遍才过
javascript·算法·leetcode
金銀銅鐵1 天前
[Python] 扩展欧几里得算法
python·数学·算法
To_OC1 天前
LC 200 岛屿数量:经典 DFS 入门题,我第一次写居然连方向都搞错了
javascript·算法·leetcode