当前位置: 首页 > 编程语言 > C#

C#LearningTutorial-OptiontoSortwithIndexFault分享

时间:2023-04-10 12:14:31 C#

SelecttoSortwithIndexFaulthttp://www.codeabbey.com/index/task_view/selection-sort其实我的选择排序没有任何问题,但我不知道为什么我没有得到正确的索引(当排序有效时!)。即输入数据:5136247980我将其分类为0123456789,就像我想要的那样。这是代码:usingSystem;使用System.Collections.Generic;使用System.Linq;使用系统文本;使用System.Threading.Tasks;namespaceSelectionSort{classProgram{staticvoidMain(string[]args){inthowMany=int.Parse(Console.ReadLine());//数组长度ListBase=newList(Array.ConvertAll(Console.ReadLine().Split(),int.Parse));//输入数组(即5136247980=>{5,1,3,6,2,4,7,9,8,0})ListOutput=newList();//存储排序数组的列表string[]ans=newstring[howMany];//存储答案的数组intloops=Base.Count();for(inti=0;i!=loops;i++){inttopID=0,topValue=0;for(intj=0;j!=Base.Count();j++){if(j==0){topID=0;topValue=Base[0];}else{if(topValue