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;

}

}

}

}

}

}

相关推荐
naturerun10 小时前
逐步插入回路法构造欧拉回路的算法
c++·算法
qizayaoshuap10 小时前
# [特殊字符] 骰子模拟器 — 鸿蒙ArkTS随机算法与动画系统设计
算法·华为·harmonyos
山顶夕景10 小时前
【DWT】计算两不等序列相似度:DWT
算法·动态规划·检索·模式识别·相似度
灯澜忆梦10 小时前
Go 语言 _JSON---序列化与反序列化
开发语言·golang·json
麻瓜老宋10 小时前
AI开发C语言应用按步走,表达式计算器calc的第四步,交互式 REPL 模式
c语言·开发语言·atomcode
猫猫不是喵喵.11 小时前
双亲委派机制与类加载过程
java·开发语言
布朗克16811 小时前
Go入门到精通-22-同步原语
开发语言·后端·golang·同步原语
奶人五毛拉人一块11 小时前
二分算法以及习题讲解
数据结构·算法·二分
帅次11 小时前
Kotlin Flow 与 StateFlow:UI 单向数据流基础
开发语言·ui·kotlin·stateflow·onlifecycle
Zachery Pole11 小时前
CCF-CSP备战NO.6【栈】
算法·深度优先