G***G 发帖数: 16778 | 1 given a set of numbers, such as ,1,5,4,2, we can sort it and the result is 5
,4,2,1 by the descending order.
but if given a set of vectors, how to sort them,
for example
a1={1,1,1,1,4}
a2={2,1,4,3,2}
a3={3,2,4,2,1}
how to sort a1, a2, and a3? | l**********1 发帖数: 5204 | 2 Please try
同主题阅读:C#里有sort多维数组的东东么?
[版面:窗口里的风景][首篇作者:midnightfire] ,
2003年11月12日
[回复]
[ 2 ]
发信人: Cklein (Calvin Klein), 信区: DotNet
标 题: Re: C#里有sort多维数组的东东么?
发信站: Unknown Space - 未名空间 (Thu Nov 13 10:49:10 2003) WWW-POST
Implement IComparable.
http://www.mitbbs.com/article_t1/DotNet/3396902_3396903_1.html
more details please go to
//www.e800.com.cn/articles/2011/0822/493921.shtml
5 | l********k 发帖数: 14844 | 3 中学数学:向量不能比较大小。你要比,可以比norm,可以比某个分量。
5
【在 G***G 的大作中提到】 : given a set of numbers, such as ,1,5,4,2, we can sort it and the result is 5 : ,4,2,1 by the descending order. : but if given a set of vectors, how to sort them, : for example : a1={1,1,1,1,4} : a2={2,1,4,3,2} : a3={3,2,4,2,1} : how to sort a1, a2, and a3?
| e**r 发帖数: 1144 | 4 你是搞哪个方向的?
怎么什么都懂啊 ....
【在 l**********1 的大作中提到】 : Please try : 同主题阅读:C#里有sort多维数组的东东么? : [版面:窗口里的风景][首篇作者:midnightfire] , : 2003年11月12日 : [回复] : [ 2 ] : 发信人: Cklein (Calvin Klein), 信区: DotNet : 标 题: Re: C#里有sort多维数组的东东么? : 发信站: Unknown Space - 未名空间 (Thu Nov 13 10:49:10 2003) WWW-POST : Implement IComparable.
| x*******6 发帖数: 262 | | g**********t 发帖数: 475 | 6 Right. LZ must define a function (rule) to compare two vectors. The
implementation depends on your programming language,but it should be fairly
easy to do it using some libraries/functions, e.g. the qsort function in C,
if the comparison is well defined.
【在 l********k 的大作中提到】 : 中学数学:向量不能比较大小。你要比,可以比norm,可以比某个分量。 : : 5
| l**********1 发帖数: 5204 | 7 How to sort a generic List
After reading this post from Steven Smith I thought I should write something about it.
Sorting a generic List is pretty straightforward if you know how to do it. With C# 2.0, anonymous
methods come at hand, as well as the little known Comparison delegate (check out this post for more
information about this class as well as other useful classes new to C# 2.0).
Ok, let's suppose we have a product class (let me save some space by using C# 3.0 syntax).
-----
Public Class Product
Implements IComparable(Of Product)
' Methods
Shared Sub New()
Product.PriceComparison = Function (ByVal p1 As Product, ByVal p2 As
Product)
Return p1.price.CompareTo(p2.price)
End Function
Product.IDComparison = Function (ByVal p1 As Product, ByVal p2 As
Product)
Return p1.id.CompareTo(p2.id)
End Function
End Sub
Public Sub New(ByVal id As Integer, ByVal prodName As String, ByVal
price As Decimal)
Me.id = id
Me.prodName = prodName
Me.price = price
End Sub
Public Function CompareTo(ByVal other As Product) As Integer
Return Me.ProductName.CompareTo(other.ProductName)
End Function
Private Shared Sub Main()
End Sub
Public Overrides Function ToString() As String
Return String.Format("Id: {0} Name: {1} Price: {2}", Me.id, Me.
prodName, Me.price)
End Function
' Properties
Public Property ProductID As Integer
Get
Return Me.id
End Get
Set(ByVal value As Integer)
Me.id = value
End Set
End Property
Public Property ProductName As String
Get
Return Me.prodName
End Get
Set(ByVal value As String)
Me.prodName = value
End Set
End Property
Public Property UnitPrice As Decimal
Get
Return Me.price
End Get
Set(ByVal value As Decimal)
Me.price = value
End Set
End Property
' Fields
Private id As Integer
Public Shared IDComparison As Comparison(Of Product)
Private price As Decimal
Public Shared PriceComparison As Comparison(Of Product)
Private prodName As String
End Class
---
//dotnetslackers.com/Community/blogs/simoneb/archive/2007/06/20/How-to-sort-a-generic-
List_3C00_T_3E00_.aspx | a*****x 发帖数: 901 | 8 depending on your rules. For example, you can sort by the length of vectors,
a1 = 1^2 + 1^2 + 1^2 + 1^2 + 4^2, etc. You can also look for their spatial
distribution. We have many software for high-content screenings that can do
it. It's not sorting though
5
【在 G***G 的大作中提到】 : given a set of numbers, such as ,1,5,4,2, we can sort it and the result is 5 : ,4,2,1 by the descending order. : but if given a set of vectors, how to sort them, : for example : a1={1,1,1,1,4} : a2={2,1,4,3,2} : a3={3,2,4,2,1} : how to sort a1, a2, and a3?
|
|