真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網站制作重慶分公司

vb.net數(shù)組排序問題 vb中數(shù)組排序的方法

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

如果你是從vb6剛過渡上vb。net,建議還是用冒泡排序法,容易理解。

主要從事網頁設計、PC網站建設(電腦版網站建設)、wap網站建設(手機版網站建設)、響應式網站建設、程序開發(fā)、微網站、小程序設計等,憑借多年來在互聯(lián)網的打拼,我們在互聯(lián)網網站建設行業(yè)積累了豐富的成都做網站、網站制作、網絡營銷經驗,集策劃、開發(fā)、設計、營銷、管理等多方位專業(yè)化運作于一體,具備承接不同規(guī)模與類型的建設項目的能力。

如果你正努力學習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語言編寫N個數(shù)字數(shù)組排序可自定義數(shù)組長度的

Dim d() As Integer

Dim n As Integer

Dim i As Integer

Dim j As Integer

Dim T As Integer

n = Val(InputBox("請輸入n,確定數(shù)組的元素個數(shù)"))

ReDim d(n)

'用隨機函數(shù)生成正整數(shù)數(shù)組

Randomize

For i = 1 To n

d(i) = Int(Rnd * 100 + 1)

Next i

'輸出

Print

For i = 1 To n

Print d(i),

Next i

'從小到大排序

For i = 1 To n - 1

For j = i + 1 To n

If d(i) d(j) Then

T = d(i)

d(i) = d(j)

d(j) = T

End If

Next j

Next i

'輸出

Print

For i = 1 To n

Print d(i),

Next i

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

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

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

'未完成時遞歸調用

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

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

End Sub

VB.NET 2維數(shù)組排序排序和賦值問題

窗體上添加3個標簽,1個按鈕,在按鈕的單擊事件里寫代碼,如下:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim a(,) As Integer = {{5, 6}, {1, 3}, {8, 9}, {72, 1}, {63, 4}}

Dim Temp As Integer

Dim i As Integer

Dim j As Integer

Dim x As Integer

Dim y As Integer

'顯示排序前的數(shù)據(jù)

Label1.Text = "排序前數(shù)據(jù):" vbCrLf

For i = 0 To 4

Label1.Text = Label1.Text a(i, 0) " " a(i, 1) vbCrLf

Next

For i = 0 To 3

For j = i + 1 To 4

If a(i, 0) a(j, 0) Then

Temp = a(i, 0)

a(i, 0) = a(j, 0)

a(j, 0) = Temp

Temp = a(i, 1)

a(i, 1) = a(j, 1)

a(j, 1) = Temp

End If

Next

Next

'顯示排序前的數(shù)據(jù)

Label2.Text = "排序后數(shù)據(jù):" vbCrLf

For i = 0 To 4

Label2.Text = Label2.Text a(i, 0) " " a(i, 1) vbCrLf

Next

'把第3行元素賦予X,Y

x = a(2, 0)

y = a(2, 1)

'輸出X,Y

Label3.Text = "X=" x vbCrLf "Y=" y

End Sub

VB.net 數(shù)組怎么按任意元素的順序排序輸出

你直接傳一個數(shù)組進去,而且是一個結構體數(shù)組,array.sort怎么知道根據(jù)結構中的哪一個屬性進行排序?放一個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結構體,換成類一樣的

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.net數(shù)組排序問題 vb中數(shù)組排序的方法
文章位置:http://weahome.cn/article/doopiip.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部