日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
vb.net數(shù)組升序排列,對數(shù)組進行升序排序的函數(shù)

二維數(shù)組排序 vb.net

Dim i As Integer, j As Integer, X As Single, Y As Single, M As Single

你所需要的網(wǎng)站建設(shè)服務(wù),我們均能行業(yè)靠前的水平為你提供.標準是產(chǎn)品質(zhì)量的保證,主要從事網(wǎng)站設(shè)計制作、網(wǎng)站制作、企業(yè)網(wǎng)站建設(shè)、手機網(wǎng)站制作設(shè)計、網(wǎng)頁設(shè)計、成都品牌網(wǎng)站建設(shè)、網(wǎng)頁制作、做網(wǎng)站、建網(wǎng)站。創(chuàng)新互聯(lián)擁有實力堅強的技術(shù)研發(fā)團隊及素養(yǎng)的視覺設(shè)計專才。

i = L

j = R

'找出數(shù)組的中點

M = MyArray((L + R) / 2, 0)

While (i = j)

'找出比中點大的數(shù)

While (MyArray(i, 0) M And i R)

i = i + 1

Wend

'找出比中點小的數(shù)

While (M MyArray(j, 0) And j L)

j = j - 1

Wend

'互換這兩個數(shù)

If (i = j) Then

X = MyArray(i, 0)

Y = MyArray(i, 1)

MyArray(i, 0) = MyArray(j, 0)

MyArray(i, 1) = MyArray(j, 1)

MyArray(j, 0) = X

MyArray(j, 1) = Y

i = i + 1

j = j - 1

End If

Wend

'未完成時遞歸調(diào)用

If (L j) Then Call QuickSort(MyArray(), L, j)

If (i R) Then Call QuickSort(MyArray(), i, R)

End Sub

VB.NET數(shù)組的排序法?

如果你是從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 數(shù)組怎么按任意元素的順序排序輸出

你直接傳一個數(shù)組進去,而且是一個結(jié)構(gòu)體數(shù)組,array.sort怎么知道根據(jù)結(jié)構(gòu)中的哪一個屬性進行排序?放一個c#的代碼你看看,VB和C#很相似的

class Program

{

static void Main(string[] args)

{

People[] p = new People[3]

{

new People{name="張三"},

new People{name="李四"},

new People{name="張二名"}

};

//重點傳一個實現(xiàn)了IComparer接口的類進去,告訴Array.Sort怎么排序

Array.Sort(p, new PeopleCompare());

foreach (var item in p)

{

Console.WriteLine(item.name);

}

Console.ReadKey();

}

}

//People結(jié)構(gòu)體,換成類一樣的

public struct People

{

public string name { get; set; }

}

//實現(xiàn)了IComparer接口的類

public class PeopleCompare : IComparer

{

public int Compare(object x, object y)

{

People p1 = (People)x ;

People p2 = (People)y;

return p1.name.CompareTo(p2.name);

}

}

VB中如何給指定的數(shù)組排序??

Private Sub Command4_Click()

Dim t As clerk, i%, j%

For i = 0 To n - 1

? For j = i To n - 2

? ? ? If a(i).vc a(j + 1).vc Then

? ? ? ? ? t = a(i): a(i) = a(j + 1): a(j + 1) = t

? ? ? End If

? Next j

Next i

Picture2.Cls

Picture2.Print "學號? ? ? ? ? 姓名? ? ? ? ? ?VC? ? ? ? ? ? VB"

Picture2.Print "---------------------------------------------"

For i = 0 To n - 1

? Picture2.Print a(i).number, a(i).name, a(i).vc, a(i).vb

? Print

Next i

End Sub

擴展資料

vb數(shù)組排序思路:

1、冒泡排序法:

位置相鄰兩數(shù)進行兩兩比較,在比較時如果發(fā)現(xiàn)前面的數(shù)比后面的數(shù)大,則進行交換,都比較完一輪后,把最大一個數(shù)放到最后,如此進行下去即可完成冒泡排序。

2、比較交換法

假設(shè)第一個數(shù)最小,然后第一個數(shù)依次與后面的每個數(shù)都進行比較, 若比較時發(fā)現(xiàn)后面的數(shù)比第一個數(shù)小, 則兩數(shù)位置進行交換, 全部都比較完算一輪,每一輪比較完后,第一個數(shù)是最小的數(shù),如此進行即可完成比較排序。

3、選擇排序

假設(shè)第一個數(shù)最小,接著記下最小數(shù)所在的位置,然后將最小數(shù)依次與后面的每一個數(shù)都進行比較,若比較時發(fā)現(xiàn)后面的數(shù)比最小的數(shù)還小,則修改最小數(shù)所在位置,全部都比較完算一輪。

每一輪比較完后,最小數(shù)所在的位置是否跟假設(shè)的是同一個位置,若不是,則最小數(shù)與第一個數(shù)進行交換位置,如此進行即可完成選擇排序。

VB中輸入10個數(shù)并按要求進行升序排序和降序的程序

Dim?AA(1?To?10)?As?Integer,?ZGCJ(1?To?10)?As?Integer,?ZDCJ(1?To?10)?As?Integer

在通用部分聲明三個數(shù)組

Private?Sub?Command1_Click()

Text1.Text?=?"":?Text2.Text?=?"":?Text3.Text?=?""

Text1.Text?=?"系統(tǒng)自動生成的十個數(shù):"??vbCrLf

For?I?=?1?To?10

AA(I)?=?0:?ZGCJ(I)?=?0:?ZDCJ(I)?=?0

Randomize

AA(I)?=?Int(Rnd?*?90?+?10)

Text1.Text?=?Text1.Text??AA(I)??Space(4)

If?I?Mod?5?=?0?Then?Text1.Text?=?Text1.Text??vbCrLf

ZGCJ(I)?=?AA(I)

ZDCJ(I)?=?AA(I)

Next?I

End?Sub

生成十個數(shù)的代碼

Private?Sub?Command2_Click()

Text2.Text?=?"":?Text3.Text?=?""

Dim?AAA?As?Integer,?BBB?As?Integer

For?I?=?1?To?9

For?J?=?I?+?1?To?10

If?ZGCJ(I)??ZGCJ(J)?Then

AAA?=?ZGCJ(I)

ZGCJ(I)?=?ZGCJ(J)

ZGCJ(J)?=?AAA

End?If

If?ZDCJ(J)??ZDCJ(I)?Then

BBB?=?ZDCJ(J)

ZDCJ(J)?=?ZDCJ(I)

ZDCJ(I)?=?BBB

End?If

Next?J

Next?I

Text2.Text?=?Text2.Text??"從大到小排列:"??vbCrLf

For?I?=?1?To?10

Text2.Text?=?Text2.Text??ZGCJ(I)??Space(4)

If?I?Mod?5?=?0?Then?Text2.Text?=?Text2.Text??vbCrLf

Next?I

Text3.Text?=?Text3.Text??"從小到大排列:"??vbCrLf

For?I?=?1?To?10

Text3.Text?=?Text3.Text??ZDCJ(I)??Space(4)

If?I?Mod?5?=?0?Then?Text3.Text?=?Text3.Text??vbCrLf

Next?I

End?Sub

排序的代碼。

如果需要自己輸入數(shù)字,可以這樣:

'如果要自己輸入數(shù)字,可以修改下面的代碼

Text1.Text?=?"":?Text2.Text?=?"":?Text3.Text?=?""

Text1.Text?=?"系統(tǒng)自動生成的十個數(shù):"??vbCrLf

For?I?=?1?To?10

AA(I)?=?0:?ZGCJ(I)?=?0:?ZDCJ(I)?=?0

Randomize

AA(I)?=?Int(Rnd?*?90?+?10)

Text1.Text?=?Text1.Text??AA(I)??Space(4)

If?I?Mod?5?=?0?Then?Text1.Text?=?Text1.Text??vbCrLf

ZGCJ(I)?=?AA(I)

ZDCJ(I)?=?AA(I)

Next?I

'----------------------------修改為:

Text1.Text?=?"":?Text2.Text?=?"":?Text3.Text?=?""

Text1.Text?=?"用戶輸入的十個數(shù):"??vbCrLf

For?I?=?1?To?10

AA(I)?=?0:?ZGCJ(I)?=?0:?ZDCJ(I)?=?0

AA(I)?=?Val(InputBox("請輸入第"??I??"個數(shù)!"))

Text1.Text?=?Text1.Text??AA(I)??Space(4)

If?I?Mod?5?=?0?Then?Text1.Text?=?Text1.Text??vbCrLf

ZGCJ(I)?=?AA(I)

ZDCJ(I)?=?AA(I)

Next?I


網(wǎng)頁標題:vb.net數(shù)組升序排列,對數(shù)組進行升序排序的函數(shù)
文章網(wǎng)址:http://www.dlmjj.cn/article/hddsjo.html