- AbstractSort
using System;
namespace Core
...{
internal abstract class AbstractSort
...{
protected int[] list;
public event SortingDelegate GreenDataChangedEvent;
public event SortingDelegate RedDataChangedEvent;
public event SortingDelegate DataChangedEvent;
protected bool stop= false;
public bool Stop 
...{
get ...{ return stop; }
set ...{ stop = value; }
}
public abstract void Sort(int[] list);
protected void GreenDataChanged(int newIndex)
...{
if(this.GreenDataChangedEvent != null)
GreenDataChangedEvent(newIndex);
}
protected void RedDataChanged(int newIndex)
...{
if(this.RedDataChangedEvent != null)
RedDataChangedEvent(newIndex);
}
protected void DataChanged(int newIndex)
...{
if(this.DataChangedEvent != null)
DataChangedEvent(newIndex);
}
protected void swap(int pos1, int pos2)
...{
int temp = list[pos1];
list[pos1] = list[pos2];
list[pos2] = temp;
DataChanged(pos1);
DataChanged(pos2);
}
protected void Finished()
...{
GreenDataChanged(-1);
RedDataChanged(-1);
}
}
}
- BubbleSort2
using System;
namespace Core
...{
internal class BubbleSort2 : AbstractSort
...{
public override void Sort(int[] list)
...{
this.list = list;
for(int i=0; i<list.Length - 1; i++)
for(int j=list.Length - 1; j>i; j--)
...{
if(stop)
return;
if(list[i]>list[j])
...{
GreenDataChanged(i);
RedDataChanged(j);
swap(i,j);
}
}
Finished();
}
}
}

/**//********************************************
* 注意!
*
* 在使用循环嵌套时,内层循环一定是递减顺序,
* 如果写反,将导致排序效率降低。
*
* 用户可尝试将上面代码中的循环嵌套改为:
*
* for(int i=0; i<list.Length - 1; i++)
* for(int j = i; j < list.Length; j++)
* {
* ......
* }
*
* 观察排序性能收到的影响。
*
*******************************************/ - BubbleSort
using System;
namespace Core
...{
internal class BubbleSort : AbstractSort
...{
public override void Sort(int[] list)
...{
this.list = list;
bool change = true;
for (int i = list.Length-1; i>0 && change; --i) 
...{
change = false;
for (int j=0; j<i; ++j)
...{
if(stop)
return;
if (list[j] > list[j+1])
...{
GreenDataChanged(j);
RedDataChanged(j+1);
swap(j,j+1);
change = true;
}
}
}
Finished();
}
}
}
- HeapSort
using System;
namespace Core
...{
internal class HeapSort : AbstractSort
...{
public override void Sort(int[] list)
...{
this.list = list;
int lastOutOfOrder;
buildHeap();
for(lastOutOfOrder = list.Length - 1; lastOutOfOrder >= 0;
lastOutOfOrder--)
...{
if(stop)
return;
swap(0, lastOutOfOrder);
heapify(0, lastOutOfOrder - 1);
}
Finished();
}
private void buildHeap()
...{
int index;
for(index = list.Length / 2 - 1; index >= 0; index--)
...{
if(stop)
return;
heapify(index, list.Length - 1);
}
}
private void heapify(int low, int high)
...{
int largeIndex;
int temp = list[low]; //copy the root node of the subtree
largeIndex = 2 * low + 1; //index of the left child
while(largeIndex <= high)
...{
if(stop)
return;
if(largeIndex < high)
if(list[largeIndex]<list[largeIndex + 1])
largeIndex = largeIndex + 1; //index of the
//largest child
if(temp>list[largeIndex]) //subtree is
//already in a heap
break;
else
...{
list[low] = list[largeIndex]; //move the larger child
GreenDataChanged(low);
//to the root
low = largeIndex; //go to the subtree to
//restore the heap
largeIndex = 2 * low + 1;
}
}
list[low] = temp; //insert temp into the tree, that is, list
RedDataChanged(low);
}
}
}
- InsertionSort
using System;
namespace Core
...{
internal class InsertionSort : AbstractSort
...{
public override void Sort(int[] list)
...{
this.list = list;
int unsortedIndex, location;
int temp;
for(unsortedIndex = 1; unsortedIndex < list.Length; unsortedIndex++)
...{
if(list[unsortedIndex] <list[unsortedIndex - 1])
...{
temp = list[unsortedIndex];
location = unsortedIndex;
while(location > 0 && list[location - 1]>temp)
...{
if(stop)
return;
list[location] = list[location - 1];
if(location == unsortedIndex)
RedDataChanged(location);
else
GreenDataChanged(location);
location--;
}
list[location] = temp;
DataChanged(location);
}
}
Finished();
}
}
}
- LRadixSort
using System;
namespace Core
...{
internal class Node
...{
public int info;
public Node link;
public Node(int info)
...{
this.info = info;
}
}
internal class Radix
...{
public Node first = null;
public Node last = null;
public int count = 0;
public void AddNode(Node newNode)
...{
if(first == null)
...{
first = newNode;
last = newNode;
}
else
...{
last.link = newNode;
last = newNode;
}
count++;
}
public void RemoveFirst()
...{
if(first == null)
return;
if(first == last)
...{
first = null;
last = null;
count = 0;
}
else
...{
first = first.link;
count--;
}
}
}
// 基数排序法
internal class LRadixSort : RadixSort
...{
public override void Sort(int[] list)
...{
throw new Exception("Wrong method call!");
}
public override void Sort(int[] list, Radix[] radix)
...{
this.list = list;
this.radix = radix;
for(int i=0; i<10; i++)
radix[i] = new Radix();
// 按最低位优先依次对各关键字进行分配和收集
for(int i=0; i<2; i++)
...{
RadixStatusChanged(RadixSortStatus.Begin);
Distribute(i);
if(stop)
return;
Collect();
if(stop)
return;
}
RadixStatusChanged(RadixSortStatus.Finished);
}
private void Distribute(int digitPlace)
...{
int digit;
digitPlace = (int)(Math.Pow(10, digitPlace));
for(int i=0; i<list.Length; i++)
...{
if(stop)
return;
if(digitPlace == 0)
digit = list[i] - list[i]/10*10;
else
digit = list[i]/digitPlace - list[i]/digitPlace/10*10;
radix[digit].AddNode(new Node(list[i]));
RadixDataChanged(digit, radix[digit].count);
}
}
private void Collect()
...{
int position = 0;
Node current;
for(int i=0; i<10; i++)
...{
current = radix[i].first;
while(current != null)
...{
if(stop)
return;
list[position] = current.info;
RadixDataCollecting(i, radix[i].count);
radix[i].RemoveFirst();
position ++;
current = radix[i].first;
}
}
}
}
} - MergeSort
using System;
namespace Core
...{
internal class MergeSort : AbstractSort
...{
public override void Sort(int[] list)
...{
this.list = list;
recMergeSort(0, list.Length - 1);
if(stop)
return;
Finished();
}
private void recMergeSort(int begin, int end)
...{
if(end > begin)
...{
int middle = (end + begin)/2;
recMergeSort(begin, middle);
recMergeSort(middle + 1, end);
Merge(begin, middle, end);
if(stop)
return;
}
}
private void Merge(int begin, int middle, int end)
...{
if(stop)
return;
int first1 = begin; //第一个数组段的当前指针
int first2 = middle + 1; //第二个数组段的当前指针
int[] temp = new int[end - begin + 1]; // 临时存储单元
int current = 0;
//开始归并处理
while(first1 != middle + 1 && first2 != end + 1)
...{
if(stop)
return;
if(list[first1] < list[first2])
...{
temp[current] = list[first1];
GreenDataChanged(first1);
if(stop)
return;
first1 ++;
}
else
...{
temp[current] = list[first2];
RedDataChanged(first2);
if(stop)
return;
first2 ++;
}
current ++ ;
}
//处理归并后留下的“尾巴”
if(first1 == middle + 1) //前半部分首先归并完
...{
while(current < temp.Length)
...{
temp[current] = list[first2];
RedDataChanged(first2);
if(stop)
return;
first2++;
current++;
}
}
else //后半部分首先归并完
...{
while(current < temp.Length)
...{
temp[current] = list[first1];
GreenDataChanged(first1);
if(stop)
return;
first1++;
current++;
}
}
//将temp中的结果记录进list当中
for(int i=0; i<temp.Length; i++)
...{
list[begin + i] = temp[i];
DataChanged(begin + i);
if(stop)
return;
}
}
}
}
- QuickSort
using System;
namespace Core
...{
internal class QuickSort : AbstractSort
...{
public override void Sort(int[] list)
...{
this.list = list;
recQuickSort(0, list.Length - 1);
Finished();
}
private void recQuickSort(int first, int last)
...{
int pivotLocation;
if(stop)
return;
if(first < last)
...{
pivotLocation = partition(first, last);
recQuickSort(first, pivotLocation - 1);
recQuickSort(pivotLocation + 1, last);
}
}
private int partition(int first, int last)
...{
int pivot;
int index, smallIndex;
swap(first, (first + last) / 2);
pivot = list[first];
smallIndex = first;
for(index = first + 1; index <= last; index++)
...{
if(stop)
return smallIndex;
if(list[index] < pivot)
...{
smallIndex++;
GreenDataChanged(smallIndex);
RedDataChanged(index);
swap(smallIndex, index);
}
}
GreenDataChanged(first);
RedDataChanged(smallIndex);
swap(first, smallIndex);
return smallIndex;
}
}
}
- RadixSort
using System;
namespace Core
...{
internal enum RadixSortStatus
...{
Begin,
Finished
}
internal abstract class RadixSort : AbstractSort
...{
protected Radix[] radix = new Radix[10];
public event RadixSortingDelegate RadixDataChangedEvent;
public event RadixSortingDelegate RadixDataCollectingEvent;
public event RadixStatusDelegate RadixStatusChangedEvent;
protected void RadixDataChanged(int digit, int index)
...{
if(this.RadixDataChangedEvent != null)
RadixDataChangedEvent(digit, index);
}
protected void RadixDataCollecting(int digit, int index)
...{
if(this.RadixDataCollectingEvent != null)
RadixDataCollectingEvent(digit, index);
}
protected void RadixStatusChanged(RadixSortStatus radixStatus)
...{
if(this.RadixStatusChangedEvent != null)
RadixStatusChangedEvent(radixStatus);
}
public abstract void Sort(int[] list, Radix[] radix);
}
}
- SelectionSort
using System;
namespace Core
...{
internal class SelectionSort : AbstractSort
...{
public override void Sort(int[] list)
...{
this.list = list;
int loc, minIndex;
for(loc = 0; loc < list.Length; loc++)
...{
minIndex = minLocation(loc, list.Length - 1);
if(minIndex == -1)
return;
swap(loc, minIndex);
RedDataChanged(loc);
}
Finished();
}
private int minLocation(int first, int last)
...{
int loc, minIndex;
minIndex = first;
for(loc = first + 1; loc <= last; loc++)
...{
if(stop)
return -1;
GreenDataChanged(loc);
if(list[loc] < list[minIndex])
minIndex = loc;
}
return minIndex;
}
}
}
- ShellSort
using System;
namespace Core
...{
internal class ShellSort : AbstractSort
...{
public override void Sort(int[] list)
...{
this.list = list;
int step = list.Length/2;
if(step>1)
ShellSwap(step);
InsertionSort();
Finished();
}
public void ShellSwap(int step)
...{
for( int i=0; i<list.Length - step; i++)
...{
if(stop)
return;
if(list[i]>list[i+step])
...{
GreenDataChanged(i);
RedDataChanged(i+step);
swap(i, i+step);
}
}
step = step/2;
if(step == 1)
return;
else
ShellSwap(step);
}
private void InsertionSort()
...{
int unsortedIndex, location;
int temp;
for(unsortedIndex = 1; unsortedIndex < list.Length; unsortedIndex++)
...{
if(list[unsortedIndex] <list[unsortedIndex - 1])
...{
temp = list[unsortedIndex];
location = unsortedIndex;
while(location > 0 && list[location - 1]>temp)
...{
if(stop)
return;
list[location] = list[location - 1];
if(location == unsortedIndex)
RedDataChanged(location);
else
GreenDataChanged(location);
location--;
}
list[location] = temp;
DataChanged(location);
}
}
}
}
}
相关推荐
LLM推理服务中的SLO感知调度优化实践
在AI服务架构中,服务级别目标(SLO)是衡量服务质量的核心指标,特别是在大型语言模型(LLM)推理场景下。SLO通常涉及TTFT(首token时间)、TPOT(每token生成时间)和端到端延迟等关键维度,这些指标直接影响用户体验和系统效率。传统FCFS调度策略由于缺乏SLO感知能力,在混合负载下往往导致资源利用率低下和SLO达标率骤降。通过引入基于模拟退火的动态调度算法和精准的延迟预测模型,可以实现对不同优先级请求的智能调度,显著提升GPU利用率和SLO达标率。这种技术方案特别适用于需要同时处理实时对话
gridControl选中某列进行排序时,怎么能让那列高亮显示
winform:首先捕获"EndSorting"事件,然后在其中加入以下代码: private void gridView_EndSorting(object sender, EventArgs e) { Color clr = gridView.Appearance.Row.BackColor; foreach (DevEx
使用这个算法我可以实现英雄联盟里英雄的走位|Java 开发实战
A算法,A(A-Star)算法是一种静态路网中求解最短路径最有效的直接搜索方法,也是解决许多搜索问题的有效算法。算法中的距离估算值与实际值越接近,最终搜索速度越快。 基本概念 首先在大学我们遇到最多的算法Dijkstra、Floyd、广度搜索、深度搜索。关于这些算法我们以后再慢慢的研究,今天的重点在A算法上。A算法是一种启发式算法。与上述几种算法不同的是A*算法在考虑起始节点的同时还会考虑到目标节点的代价。 在A*算法中我们给每个节点都定义一些属性。最基本的就是下文提到的三基数-这里的三基数是我自己定义.
C# Collection 排序
Collection<int> aa = new Collection<int>(); aa.Add(1); aa.Add(2); aa.Add(3); aa.Add(1); int[] arr = new int[aa.Count]; aa...
机器视觉应用工程师职位深度解析与面试指南
广东奥普特科技招聘机器视觉应用工程师,要求大专以上理工科专业背景,熟悉C/C++或PLC编程,具备自动化设备调试经验。岗位职责包括视觉项目方案评估、系统安装调试、售后技术支持及异常处理,需接受外派出差。该职位面向专业对口的应届生或实习生,强调动手能力、沟通技巧和吃苦耐劳精神。机器视觉工程师需掌握图像处理算法、硬件配置等核心技术,在工业自动化领域具有良好发展前景。求职者应注重编程能力和实践经验的积累,以胜任这一技术密集型岗位。
构建栅格地图matlab代码
1 使用MATLAB实现地图栅格化 效果图如下所示 图1 ...
C# List集合排序方法小结
本文介绍了C#中List集合的三种排序方法:1) 通过实现IComparer接口创建比较类;2) 使用委托(Comparison)进行排序;3) 使用Lambda表达式简化排序代码。以People类(包含name和age属性)为例,演示了如何按年龄对对象列表进行排序。第一种方法需要创建单独的PeopleCompare类,第二种采用委托方式更简洁,第三种Lambda表达式最为精简。这三种方式都能实现自定义排序,开发者可根据需求选择最适合的方法。
把静态前端托管进 SAP BTP:HTML5 Application Deployer 与企业级内容部署全攻略
本文介绍了在SAP BTP Cloud Foundry环境中使用HTML5 Application Repository托管前端静态资源的工程化实践。通过HTML5 Application Deployer工具,结合MTA描述、路由配置和服务实例,实现前后端解耦和标准化部署。文章详细阐述了目录结构、关键配置文件、MTA编排以及构建部署流程,并针对大体积前端资源提供了GACD和异步上传两种解决方案。最后说明了如何与AppRouter协同工作,使部署内容可供终端用户访问。这套方法使前端更新无需重启后端,支持团队
排序算法文章集锦
以下收集较好的排序算法文章: 八大排序算法的 Python 实现:http://python.jobbole.com/82270/ 视觉直观感受 7 种常用的排序算法:http://blog.jobbole.com/11745/ 可视化对比十多种排序算法(C#版):http://blog.jobbole.com/72850/ 转载于:https://www.cnblogs.com...
基于simulink构建一个完整的航空航天器姿态控制与导航仿真模型
航空航天器的姿态控制与导航系统是确保飞行器稳定运行和精确执行任务的核心技术。其目标是通过传感器获取飞行器的状态信息,并利用控制器调整飞行器的姿态,使其按照预定轨迹飞行。基于MATLAB/Simulink平台进行航空航天器姿态控制与导航系统的建模与仿真,可以帮助研究者验证算法性能并优化系统的动态响应。本项目旨在构建一个完整的航空航天器姿态控制与导航仿真模型,包括飞行器动力学建模、传感器模块设计、控制器实现以及导航算法仿真,并通过仿真分析其性能。
CRC_16---ModBus 计算方法及代码实现
1、 CRC寄存器初始值为 0xFFFF;即16个字节全为1; 2、 CRC-16 / ModBus的多项式0xA001H (1010 0000 0000 0001B) ; ‘H’表示16进制数,‘B’表示二进制数。 计算步骤为: (1).预置 16 位寄存器为十六进制 0xFFFF(即全为 1) ,称此寄存器为 CRC 寄存器; (2).把第一个 8 位数据与 16 位 CRC 寄存器的低位相异或,把结果放于 CRC 寄存器; (3).检测相异或后的CRC寄存器的最低位,若最低位为1,CRC寄存器
转载博客
http://www.cnblogs.com/linjiqin/archive/2012/04/01/2428695.html [数据库设计三大范式]
【深度学习新浪潮】李飞飞团队VAGEN框架深度解析:让VLM智能体学会“三思而后行“
VAGEN框架的真正价值,不仅在于性能指标的突破,更在于重新定义了VLM智能体的发展方向——人工智能的进步不应只追求"做得对",更要实现"想得清"。李飞飞团队通过强制显式思考、动态表示适配和精细化奖励三大创新,让智能体第一次具备了可解释的世界建模能力。正如人类通过"观察-预测-行动"认识世界,VAGEN为AI注入的这种思考范式,或许正是通往通用人工智能的关键一步。对于开发者而言,开源的VAGEN框架不仅提供了强大的工具,更揭示了一个重要理念:让AI学会思考,比让它学会执行更重要。
大神网址
1.关于排序 http://blog.youkuaiyun.com/llw01/article/details/11815673 2.尔雅题库 erya.hang.im 3.日历网站 18829289889 9MgMth http://blog.youkuaiyun.com/qq973177663/article/details/39560753 4.袁国政的C#委托 http://www.tracef
Statistics and Machine Learning Toolbox
Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具
TMS_WebGMaps_1.9.8.0_Full_Source
TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder
经典博文收集(强烈推荐!!!)
经典博文收集(强烈推荐!!!)
SAP B1中文培訓教材_SDK
公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说
C算法宝库终极指南:200+核心算法实现原理与实战应用
C#算法库是一个全面的开源项目,汇集了200多种经典算法的C#实现,为开发者和学习者提供了宝贵的教育资源。这个项目覆盖了计算机科学、数学、数据科学和机器学习等多个领域,是掌握算法原理和提升编程技能的绝佳工具。 ## 🎯 项目概述与核心价值 这个C#算法库不仅仅是一个代码集合,更是一个**完整的算法学习体系**。每个算法都经过精心实现和测试,确保代码质量和可读性。无论是初学者还是资深开发者,都
NTscan扫描工具
ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。
学好算法?不花钱好好看这个 GitHub 项目就够了!
点击上方“小白学视觉”,选择加"星标"或“置顶”重磅干货,第一时间送达 转自机器之心不想做低级码农,不想成为前端抠图达人或是后台「增删改查」小王子?那你可能需要好好复...
经典博文收集
[01]汤姆大叔系列博文 [01]大叔手记全集 [02]Knockout应用开发指南 [03]微软ASP.NET站点部署指南 [04]HTML5学习笔记简明版 [05]大叔翻译博文索引 [06]深入理解JavaScript系列 [02]推荐单页篇 [01]大型JavaScript应用架构模式 [02]别再让面试官问你单例 [03]大叔的一次面试经...
ESP32-P4 SD卡共存:SD卡与Wi-Fi/BLE无线通信如何做到互不干扰
本文以「ESP32-P4 SD卡共存」为主题,基于 ESP-IDF 框架,讲清 ESP32-P4 上 SD 卡与 Wi-Fi/BLE 无线通信稳定共存的一套配置做法:从 SDMMC 槽位划分、LDO 上电、文件系统挂载参数,到频率优化与故障排查。 [ 主要内容: docker,k8s/k3s/rancher/helm,ai平台,大数据平台架构(presto),airflow调度,istio/linkerd服务网格,kubeflow分布式训练和服务化,网关(kong/nginx), 消息队列,prometheus监控生态,efk日志系统 ...
Files 文件管理器:免费开源、双面板+多标签的 Windows 文件管理完整教程
Files 是一款免费开源的 Windows 文件管理器,把标签页、双面板、文件预览、文件标签和 Git 操作整合进同一个界面,目标是直接替代系统资源管理器。它基于 C# 和 WinUI 3 构建,社区持续维护,装完就能用,不花钱。 ## 为什么你想换掉资源管理器 做 A 任务的文件在 D 盘,要挪到 E 盘的项目目录,得先开第二个窗口,再跨屏拖拽;想确认一个 PDF 里写了什么,得双击打开、
368



被折叠的 条评论
为什么被折叠?



