折半插入排序

using System;

using System.Collections;

using System.Runtime.CompilerServices;

namespace HelloWorldApplication

{

struct KeyType

{

public int key;

};

struct SqList

{

public KeyType\[\] r;

public int length;

};

class HelloWorld

{

static int maxSize = 100;

private static void BInsertSort(SqList l)

{

KeyType temp;

Console.WriteLine("排序前:l.key:{0}, l.length:{1}", StrSqList(l), l.length);

for (int i = 1; i < l.length; i++)

{

temp = l.ri;

int low = 0;

int high = i - 1;

while (low <= high)

{

int m = (low + high) / 2;

if (temp.key < l.rm.key)

{

high--;

} else

{

low++;

}

}

for (int j = i - 1; j >= high + 1; j--)

{

l.rj + 1.key = l.rj.key;

}

l.rhigh + 1.key = temp.key;

// Console.WriteLine("排序中:l.key:{0}, l.length:{1}", StrSqList(l), l.length);

}

Console.WriteLine("排序后:l.key:{0}, l.length:{1}", StrSqList(l), l.length);

}

private static string StrSqList(SqList l)

{

int \[\]a = new intl.length;

for(int i=0; i < l.length; i++)

{

ai = l.ri.key;

}

return string.Join(",", a);

}

static void Main(string\[\] args)

{

/* 我的第一个 C# 程序*/

// 初始化线性表

SqList l;

l.r = new KeyTypemaxSize;

int \[\]r = new int\[\]{49,38,65,97,76,13,27,49 };

KeyType key;

for(int i = 0; i < r.Length; i++)

{

key.key = ri;

l.ri = key;

}

l.length = r.Length;

// 调用排序算法

BInsertSort(l);

Console.ReadKey();

}

}

}

相关推荐
hanhahai12 分钟前
指针与函数(函数指针与指针函数)
算法
吴可可12331 分钟前
多段线扩展数据的应用场景
c#
ValhallaCoder38 分钟前
Leetcode-hot100(2026.08.17)
python·算法·leetcode
泡沫冰@1 小时前
GO 语言基础
开发语言·算法·golang
慧都小妮子2 小时前
C# 实现AI合同审查:从读取、风险标注到批量签发
ai·自然语言处理·c#·.net·办公自动化·ai合同审查·文档ai代理
luj_17682 小时前
元设计的诱惑与现实
c语言·开发语言·c++·经验分享·算法
小星星闪亮登场2 小时前
ST表--倍增思想
开发语言·数据结构·c++·算法·思维
马可家的菠萝3 小时前
Vue3 + Canvas 手绘笔记工程化实践:别把画布只当成一张 PNG
前端·vue.js·算法
watersink3 小时前
机器学习极大似然估计与EM算法
人工智能·算法·机器学习
叠层归一研究院3 小时前
如何用程序搭建一个 AGI 种子系统(一):从向量种子到无限生长引擎
人工智能·python·算法·机器学习·agi