谢谢
10 个解决方案
#1
那位大神解答一下?
谢谢
谢谢
#3
排序要有规则的啊。你规则都不说谁知道你怎么排???
#4
字符串数组进行字典排序??
描述的好蛋疼。。。
描述的好蛋疼。。。
#5
没有规则怎么排序?!
#6
void Main()
{
string[] fileList =new string[] {"list_1.htnl","list_10.html","list_100.html","list_111.html","list_109.html","list_11.html"};
fileList= fileList.OrderBy(s =>int.Parse( Regex.Match(s, @"\d+").Value)).ToArray();
foreach (string s in fileList)
{
Console.WriteLine(s);
}
}
/*
结果:
list_1.htnl
list_10.html
list_11.html
list_100.html
list_109.html
list_111.html
/*
{
string[] fileList =new string[] {"list_1.htnl","list_10.html","list_100.html","list_111.html","list_109.html","list_11.html"};
fileList= fileList.OrderBy(s =>int.Parse( Regex.Match(s, @"\d+").Value)).ToArray();
foreach (string s in fileList)
{
Console.WriteLine(s);
}
}
/*
结果:
list_1.htnl
list_10.html
list_11.html
list_100.html
list_109.html
list_111.html
/*
#7
说白了 就是按后面的数字排序?
#8
用list的Sort方法,自己提供比较器
#9
static void Main(string[] args)
{
//测试序列,实际系统中,如果得到乱序序列则应该先使用排序算法进行排序
int[] data = new int[] { 0, 2, 3, 4, 6, 7, 8, 10 };
Console.WriteLine("测试序列为");
for (int i = 0; i < data.Length; i++)
Console.Write("{0},", data[i]);
Console.Write("\r\n");
Console.WriteLine("查找元素{0},查找结果为:{1}", 3, Search(data, 3));
Console.WriteLine("查找元素{0},查找结果为:{1}", 0, Search(data, 0));
Console.WriteLine("查找元素{0},查找结果为:{1}", 10, Search(data, 10));
Console.WriteLine("查找元素{0},查找结果为:{1}", 9, Search(data, 9));
Console.Read();
}
/// <summary>
/// 二分查找算法
/// </summary>
/// <param name="data">有序数组</param>
/// <param name="val">查找的值</param>
/// <returns>如果找到,则返回在数组中的下标,否则返回-1</returns>
static int Search(int[] data, int val)
{
if (data.Length <= 0)//如果数组为空,则直接返回-1
return -1;
//设置初始上下为数组的上下限
int low = 0;
int high = data.Length - 1;
while (low <= high)//循环二分查找,直接找到指定元素或者查找完毕
{
int middle = (low + high) / 2;//这里时行二分
if (data[middle] == val)//找到指定元素
return middle;
else if (data[middle] < val)//对二分后较大的那一半序列进行查找
low = middle + 1;
else//对二分后较小的那一序列进行查找
high = middle - 1;
}
return -1;//二分结束仍没有找到指定元素
}
{
//测试序列,实际系统中,如果得到乱序序列则应该先使用排序算法进行排序
int[] data = new int[] { 0, 2, 3, 4, 6, 7, 8, 10 };
Console.WriteLine("测试序列为");
for (int i = 0; i < data.Length; i++)
Console.Write("{0},", data[i]);
Console.Write("\r\n");
Console.WriteLine("查找元素{0},查找结果为:{1}", 3, Search(data, 3));
Console.WriteLine("查找元素{0},查找结果为:{1}", 0, Search(data, 0));
Console.WriteLine("查找元素{0},查找结果为:{1}", 10, Search(data, 10));
Console.WriteLine("查找元素{0},查找结果为:{1}", 9, Search(data, 9));
Console.Read();
}
/// <summary>
/// 二分查找算法
/// </summary>
/// <param name="data">有序数组</param>
/// <param name="val">查找的值</param>
/// <returns>如果找到,则返回在数组中的下标,否则返回-1</returns>
static int Search(int[] data, int val)
{
if (data.Length <= 0)//如果数组为空,则直接返回-1
return -1;
//设置初始上下为数组的上下限
int low = 0;
int high = data.Length - 1;
while (low <= high)//循环二分查找,直接找到指定元素或者查找完毕
{
int middle = (low + high) / 2;//这里时行二分
if (data[middle] == val)//找到指定元素
return middle;
else if (data[middle] < val)//对二分后较大的那一半序列进行查找
low = middle + 1;
else//对二分后较小的那一序列进行查找
high = middle - 1;
}
return -1;//二分结束仍没有找到指定元素
}
#10
字典排序就是按照字典目录的排序规则排序
比如说 100 0 1 11 10 2 3 4
排序后
就
0
1
10
100
11
2
3
4
比如说 100 0 1 11 10 2 3 4
排序后
就
0
1
10
100
11
2
3
4
#1
那位大神解答一下?
谢谢
谢谢
#2
#3
排序要有规则的啊。你规则都不说谁知道你怎么排???
#4
字符串数组进行字典排序??
描述的好蛋疼。。。
描述的好蛋疼。。。
#5
没有规则怎么排序?!
#6
void Main()
{
string[] fileList =new string[] {"list_1.htnl","list_10.html","list_100.html","list_111.html","list_109.html","list_11.html"};
fileList= fileList.OrderBy(s =>int.Parse( Regex.Match(s, @"\d+").Value)).ToArray();
foreach (string s in fileList)
{
Console.WriteLine(s);
}
}
/*
结果:
list_1.htnl
list_10.html
list_11.html
list_100.html
list_109.html
list_111.html
/*
{
string[] fileList =new string[] {"list_1.htnl","list_10.html","list_100.html","list_111.html","list_109.html","list_11.html"};
fileList= fileList.OrderBy(s =>int.Parse( Regex.Match(s, @"\d+").Value)).ToArray();
foreach (string s in fileList)
{
Console.WriteLine(s);
}
}
/*
结果:
list_1.htnl
list_10.html
list_11.html
list_100.html
list_109.html
list_111.html
/*
#7
说白了 就是按后面的数字排序?
#8
用list的Sort方法,自己提供比较器
#9
static void Main(string[] args)
{
//测试序列,实际系统中,如果得到乱序序列则应该先使用排序算法进行排序
int[] data = new int[] { 0, 2, 3, 4, 6, 7, 8, 10 };
Console.WriteLine("测试序列为");
for (int i = 0; i < data.Length; i++)
Console.Write("{0},", data[i]);
Console.Write("\r\n");
Console.WriteLine("查找元素{0},查找结果为:{1}", 3, Search(data, 3));
Console.WriteLine("查找元素{0},查找结果为:{1}", 0, Search(data, 0));
Console.WriteLine("查找元素{0},查找结果为:{1}", 10, Search(data, 10));
Console.WriteLine("查找元素{0},查找结果为:{1}", 9, Search(data, 9));
Console.Read();
}
/// <summary>
/// 二分查找算法
/// </summary>
/// <param name="data">有序数组</param>
/// <param name="val">查找的值</param>
/// <returns>如果找到,则返回在数组中的下标,否则返回-1</returns>
static int Search(int[] data, int val)
{
if (data.Length <= 0)//如果数组为空,则直接返回-1
return -1;
//设置初始上下为数组的上下限
int low = 0;
int high = data.Length - 1;
while (low <= high)//循环二分查找,直接找到指定元素或者查找完毕
{
int middle = (low + high) / 2;//这里时行二分
if (data[middle] == val)//找到指定元素
return middle;
else if (data[middle] < val)//对二分后较大的那一半序列进行查找
low = middle + 1;
else//对二分后较小的那一序列进行查找
high = middle - 1;
}
return -1;//二分结束仍没有找到指定元素
}
{
//测试序列,实际系统中,如果得到乱序序列则应该先使用排序算法进行排序
int[] data = new int[] { 0, 2, 3, 4, 6, 7, 8, 10 };
Console.WriteLine("测试序列为");
for (int i = 0; i < data.Length; i++)
Console.Write("{0},", data[i]);
Console.Write("\r\n");
Console.WriteLine("查找元素{0},查找结果为:{1}", 3, Search(data, 3));
Console.WriteLine("查找元素{0},查找结果为:{1}", 0, Search(data, 0));
Console.WriteLine("查找元素{0},查找结果为:{1}", 10, Search(data, 10));
Console.WriteLine("查找元素{0},查找结果为:{1}", 9, Search(data, 9));
Console.Read();
}
/// <summary>
/// 二分查找算法
/// </summary>
/// <param name="data">有序数组</param>
/// <param name="val">查找的值</param>
/// <returns>如果找到,则返回在数组中的下标,否则返回-1</returns>
static int Search(int[] data, int val)
{
if (data.Length <= 0)//如果数组为空,则直接返回-1
return -1;
//设置初始上下为数组的上下限
int low = 0;
int high = data.Length - 1;
while (low <= high)//循环二分查找,直接找到指定元素或者查找完毕
{
int middle = (low + high) / 2;//这里时行二分
if (data[middle] == val)//找到指定元素
return middle;
else if (data[middle] < val)//对二分后较大的那一半序列进行查找
low = middle + 1;
else//对二分后较小的那一序列进行查找
high = middle - 1;
}
return -1;//二分结束仍没有找到指定元素
}
#10
字典排序就是按照字典目录的排序规则排序
比如说 100 0 1 11 10 2 3 4
排序后
就
0
1
10
100
11
2
3
4
比如说 100 0 1 11 10 2 3 4
排序后
就
0
1
10
100
11
2
3
4