当前位置:网站首页>Array sort 3
Array sort 3
2022-07-26 04:29:00 【VB.Net】
Copyright notice : This article is an original blog article , For reprint, please indicate the source of this article and the author's network name in a prominent position , May not be used for commercial purposes without the permission of the author .
In the last section, I actually used String Of CompareTo Methods for comparison , It's not very intuitive . In this section, it is easier to see that the return negative value is in the front .
In poker games fight against landlords It is usually according to the king 、 Xiao Wang 、2、A、K、Q、J、10、……、3 The order of size . When doing code design, you can first put it into the array according to the card name , Then sort according to the position of the obtained card names in the array , The specific class code is as follows :
Public Class poker
Implements IComparable(Of poker)
Public Property cardid As Integer
Public Property cardName As String
Private cards() As String = {"Red Joker", "Black Joker", "Tow",
"Ace", "King", "Queen", "Jack",
"Ten", "Nine", "Eight", "Seven", "Six", "Five", "Four", "Three"}
Sub New(ByVal id As Integer, ByVal Name As String)
Me.cardid = id
Me.cardName = Name
End Sub
Public Function CompareTo(other As poker) As Integer Implements IComparable(Of poker).CompareTo
Dim pos1 As Integer
Dim pos2 As Integer
pos1 = Array.IndexOf(cards, cardName)
pos2 = Array.IndexOf(cards, other.cardName)
If pos1 <= pos2 Then
Return -1
Else
Return 1
End If
End Function
Public Overrides Function ToString() As String
Return cardid & ":" & cardName
End Function
End ClassThe code :
If pos1 <= pos2 Then
Return -1
Else
Return 1
End If
It can be simplified as :
Return (pos1 - pos2)
stay Sub Main Use the following in :
Dim testpoker() As poker = New poker() {
New poker(1, "Tow"),
New poker(2, "Ace"),
New poker(3, "Five"),
New poker(4, "Red Joker"),
New poker(5, "Seven"),
New poker(6, "Queen"),
New poker(7, "Three"),
New poker(8, "Nine")
}
Array.Sort(testpoker)
For i As Integer = 0 To testpoker.Length - 1
Console.WriteLine(testpoker(i).ToString & " ")
Next
Console.ReadKey()The sorting output is shown in the following figure :

because .net Under the platform C# and vb.NET Very similar , This article can also be C# Provide reference for enthusiasts .
Learn more vb.net knowledge , Please see vb.net course Catalog
边栏推荐
- Day26 job
- 数据仓库
- Wu Enda's machine learning after class exercises - logical regression
- Sweet butter
- Low cost, fast and efficient construction of digital collection app and H5 system, professional development of scallop technology is more assured!
- egg-ts-sequelize-CLI
- Keil V5 installation and use
- 生活相关——减少期待,更快乐
- Several methods of realizing high-low byte or high-low word exchange in TIA botu s7-1200
- 1. Mx6u-alpha development board (main frequency and clock configuration experiment)
猜你喜欢

The auxiliary role of rational cognitive educational robot in teaching and entertainment

机器学习之桑基图(用于用户行为分析)

Recommendation | scholar's art and Tao: writing papers is a skill

Dijango learning

Recommendation Book Educational Psychology: a book for tomorrow's teachers~

YAPI安装

这种是我的vs没连上数据库吗

Keil V5 installation and use

青少年创客教育的创意设计原理

Tutorial on using the one click upgrade function of the rtsp/onvif protocol video platform easynvr service
随机推荐
Life related -- the heartfelt words of a graduate tutor of Huake (mainly applicable to science and Engineering)
When you try to delete all bad code in the program | daily anecdotes
Optimization analysis and efficiency execution of MySQL
Day26 job
SEGGER Embedded Studio找不到xxx.c或者xxx.h文件
UE4 键盘控制开关灯
How to download the supplementary literature?
人脸数据库收集总结
Can literature | relationship research draw causal conclusions
How is the launch of ros2 different?
一、基础入门
Huawei executives talk about the 35 year old crisis. How can programmers overcome the worry of age?
egg-ts-sequelize-CLI
解决:RuntimeError: Expected object of scalar type Int but got scalar type Double
2022杭电多校 DOS Card(线段树)
Threadpooltaskexecutor and ThreadPoolExecutor
Phaser(一):平台跳跃收集游戏
生活相关——一个华科研究生导师的肺腑之言(主要适用于理工科)
1. Excel的IF函数
一个sql server查询截止某个日期最新的记录