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;

}

}

}

}

}

}

相关推荐
爱吃火鸡面呀5 分钟前
Doris 数据划分实战:List 分区、分桶列与桶数选择
数据结构·list
万化冥合16 分钟前
怎么批量把 Word 转 PDF?
python·pdf·c#·word
qq_4017004124 分钟前
Qt Modbus 源码剖析:从 QModbusClient 到工业级通信框架
开发语言·qt·系统架构
星夜离尘5626 分钟前
MATLAB 角度解缠遇到丢样:先分段,再说明圈数为什么不可恢复
开发语言·matlab
我命由我1234534 分钟前
6-2.Python 异常处理 - 异常捕获(捕获指定异常、常见异常类型、异常信息)
java·运维·开发语言·python·http·https·java-ee
ZoeLandia37 分钟前
React08:自定义 Hook
开发语言·前端·react.js·typescript
ZhengEnCi44 分钟前
一亿条数据取前100条完全指南:从全量排序到分块流式最小堆的4种解法实测
python·算法·排序算法
zaizai10071 小时前
STL深度剖析2
java·c++·算法
染指11101 小时前
157.Agent-LangGraph-工具(实现ReAct Agent模式)
开发语言·人工智能·python·langchain·agents
程序猿乐锅1 小时前
【从0-1学习Python | 第九篇】继承
开发语言·后端·python·学习·fastapi