网站建设资讯

NEWS

网站建设资讯

vb.net数组倒序,C#数组倒序

VB.NET是否有数组排序方法

游戏中遇到这样的问题,需要将一组已知的数据打乱,按照以前和现在的做法,总结了以下方法。

成都创新互联从2013年成立,先为剑河等服务建站,剑河等地企业,进行企业商务咨询服务。为剑河企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

方法一,最笨的菜鸟方法,也是容易想到的(幸好我没想过这种方法 :))

从已知数组中随机一个数,然后加入到另一个数组中,在加入之前,先检查是否已经加入过。

这种方法有很大运气成分,且数据越大,效率越低,超过一定数目,则程序几乎无法执行,会一直卡在那里,代码:

[java] view plain copy

package com.test;

import java.util.Random;

public class TestArray {

public static int runCount =0;//用于记录方法运算次数

VB.NET数组的排序法?

如果你是从vb6刚过渡上vb。net,建议还是用冒泡排序法,容易理解。

如果你正努力学习vb。net的方法,推荐一个例子如下:

Imports System

Imports System.Collections

Public Class SamplesArray

Public Class myReverserClass

Implements IComparer

' Calls CaseInsensitiveComparer.Compare with the parameters reversed.

Function Compare(x As Object, y As Object) As Integer _

Implements IComparer.Compare

Return New CaseInsensitiveComparer().Compare(y, x)

End Function 'IComparer.Compare

End Class 'myReverserClass

Public Shared Sub Main()

' Creates and initializes a new Array and a new custom comparer.

Dim myArr As [String]() = {"The", "QUICK", "BROWN", "FOX", "jumps", "over", "the", "lazy", "dog"}

Dim myComparer = New myReverserClass()

' Displays the values of the Array.

Console.WriteLine("The Array initially contains the following values:")

PrintIndexAndValues(myArr)

' Sorts a section of the Array using the default comparer.

Array.Sort(myArr, 1, 3)

Console.WriteLine("After sorting a section of the Array using the default comparer:")

PrintIndexAndValues(myArr)

' Sorts a section of the Array using the reverse case-insensitive comparer.

Array.Sort(myArr, 1, 3, myComparer)

Console.WriteLine("After sorting a section of the Array using the reverse case-insensitive comparer:")

PrintIndexAndValues(myArr)

' Sorts the entire Array using the default comparer.

Array.Sort(myArr)

Console.WriteLine("After sorting the entire Array using the default comparer:")

PrintIndexAndValues(myArr)

' Sorts the entire Array using the reverse case-insensitive comparer.

Array.Sort(myArr, myComparer)

Console.WriteLine("After sorting the entire Array using the reverse case-insensitive comparer:")

PrintIndexAndValues(myArr)

End Sub 'Main

Public Shared Sub PrintIndexAndValues(myArr() As [String])

Dim i As Integer

For i = 0 To myArr.Length - 1

Console.WriteLine(" [{0}] : {1}", i, myArr(i))

Next i

Console.WriteLine()

End Sub 'PrintIndexAndValues

End Class 'SamplesArray

'This code produces the following output.

'

'The Array initially contains the following values:

' [0] : The

' [1] : QUICK

' [2] : BROWN

' [3] : FOX

' [4] : jumps

' [5] : over

' [6] : the

' [7] : lazy

' [8] : dog

'

'After sorting a section of the Array using the default comparer:

' [0] : The

' [1] : BROWN

' [2] : FOX

' [3] : QUICK

' [4] : jumps

' [5] : over

' [6] : the

' [7] : lazy

' [8] : dog

'

'After sorting a section of the Array using the reverse case-insensitive comparer:

' [0] : The

' [1] : QUICK

' [2] : FOX

' [3] : BROWN

' [4] : jumps

' [5] : over

' [6] : the

' [7] : lazy

' [8] : dog

'

'After sorting the entire Array using the default comparer:

' [0] : BROWN

' [1] : dog

' [2] : FOX

' [3] : jumps

' [4] : lazy

' [5] : over

' [6] : QUICK

' [7] : the

' [8] : The

'

'After sorting the entire Array using the reverse case-insensitive comparer:

' [0] : the

' [1] : The

' [2] : QUICK

' [3] : over

' [4] : lazy

' [5] : jumps

' [6] : FOX

' [7] : dog

' [8] : BROWN

vb.net数组逆序的程序

参考

#includestdio.h

int main()

{int n,i,j,t,a[200];

printf("数组中数的个数:");

scanf("%d",n);

printf("数组中的数:\n");

for(i=0;in;i++)

{

a[i]=i+1;

printf("%d ",a[i]);

}

for(i=0,j=n-1;ij;i++,j--)

{t=a[i];a[i]=a[j];a[j]=t;}

printf("\n逆序后的数组:\n");

for(i=0;in;i++)

printf("%d ",a[i]);

printf("\n");

getch();

return 0;

}

VB.NET中字符串倒序的问题

好象有个StrReverse函数是直接反转字符串的吧..

我平时用的是VB6.但是.NET中应该也是可以用MID的

你注意看FOR 是从len-1到0的..而mid中是不允许出现0的..

你看看MID运行不了时,是不是返回I是0的时间

改成:

For i = Len(sstr) To 1 Step -1

试试了?


名称栏目:vb.net数组倒序,C#数组倒序
文章网址:http://cdweb.net/article/dseeedh.html