我在数组中运算时,经常提示:
Make sure that the maximum index on a list is less than the size
我的数组也没有越界,不知道为什么???
Make sure that the maximum index on a list is less than the size
我的数组也没有越界,不知道为什么???
解决方案 »
- 页面传值问题
- C#.net div 正规表达式问题
- 如何转换当前时间2009年5月25日17点30分为200905251730241格式,并赋值给textbox?
- 如何从一个已有项目中提取出类图?
- c#.net vs2005.net 桌面应用程序开发、web应用程序开发、数据库应用开发、多层架构应用、gis开发的好站点、博客、资源等贴出来大家共享!
- VS2008 如何将数据库打包到安装程序中(ACCESS数据库)
- 问一个比较特殊的NET MD5加密问题
- 给用户控件上的文本框绑定对象属性
- winForm1里datagirdview增删改
- Delegae 类 和 delegate关键字有有啥区别呢
- C#软件如何移置到手机
- 请各位大侠帮帮忙解决有关WinHTMLEditorControl使用出现的问题
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace MergeSort1
{
class Program
{
static void Main(string[] args)
{
int[] arr = new int[] { 9, 5, 8, 4, 7, 3, 6, 2, 1 };
//for(int i = 0; i < arr.Length;i++ )
MergeSortFunction(arr, 0, arr.Length);
}
public static void MergeSortFunction(int[] array, int first,int last)
{
if(first < last)
{
int mid = (first + last) / 2;
MergeSortFunction(array,first,mid);
MergeSortFunction(array,mid+1,last);
MergeSort(array, first, mid, last);
}
}
public static void MergeSort(int[] arr, int first, int mid, int last)
{
int valueA = first;
int valueB = mid+1;
int[] temp=new int[last+1];
int i=0;
while(valueA<=mid&&valueB<=last)
{
if(arr[valueA]>=arr[valueB])
{
temp[i++]=arr[valueB++];
}
else
{
temp[i++]=arr[valueA++];
}
}
while(valueA<=mid)
{
temp[i++]=arr[valueA++];
}
while(valueB<=last)
{
temp[i++]=arr[valueB++];
}
for(int j = first; j <= last; j++)
{
arr[j] = temp[j];
}
foreach(int n in arr)
Console.Write(n + " ");
Console.ReadLine();
}
}
}
我的这个归并排序,错在哪里??