折半插入排序

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();

}

}

}

相关推荐
格林威37 分钟前
工业相机Chunk功能全解析:图像嵌入时间戳、编码器元数据(附堡盟C#代码)
开发语言·人工智能·数码相机·计算机视觉·c#·视觉检测·工业相机
Arbori_262151 小时前
Rider 调试 VisionMaster C# 用户脚本
c#·visionmaster
稚南城才子,乌衣巷风流2 小时前
ST 表(Sparse Table)算法详解:原理、实现与应用
算法
hold?fish:palm2 小时前
9 找到字符串中所有字母异位词
c++·算法·leetcode
Sw1zzle3 小时前
算法入门(六):贪心算法 - 基础入门(Leetcode 121/455/860/376/738)
算法·leetcode·贪心算法
青山木3 小时前
Hot 100 --- 岛屿数量
java·数据结构·算法·leetcode·深度优先·广度优先
不会就选b3 小时前
算法日常・每日刷题--<归并排序>1
数据结构·算法
危桥带雨3 小时前
排序算法(快排、归并、计数、基数排序)
数据结构·算法·排序算法
啦啦啦啦啦zzzz3 小时前
算法:回溯算法
c++·算法·leetcode