|
-
Jul 10th, 2004, 06:09 AM
#1
Thread Starter
Member
Sorting a Collection
I am having a problem with a Collection. I have created a card class that holds the number (1-13) and a suit (C, D, H, S). I then have created a collection that holds 5 card objects. What I am attempting to do is sort the collection by card.number from lowest to highest.
Ex: 3H, 9C, 2D, 5S, 3C
To
2D, 3H, 3C, 5S, 9C
I have tried using multidimentional arrays, and collections. I would like to use something along the lines I use with a single dimensional array:
Array.Sort(myArray)
Unfortunatly this method dosent work with collections or multidimentional arrays. If you have a solution on how I should approach this I would really appreciat it.
-Thanks
-
Jul 10th, 2004, 08:07 AM
#2
Fanatic Member
You need to write your own sort method. There are several methods to do so: Quick Sort, Bubble Sort, Insertion Sort, etc... find the one that best fits your situation and implement it in your collection.
Alternatively, you can make sure that when you add items to your collection that they are inserted in the correct location - so the sorting is done when items are added.
-
Jul 10th, 2004, 08:13 AM
#3
PowerPoster
Hi,
Create a single dimension string array; enter the values required, BUT it is easier if you accord letters instead of numbers to the card values and separate the value from the suit by a space
e.g. 3 hearts is C H: Jack Clubs is K C
Then store the value in a single dimension string array as sort as normal.
I
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 10th, 2004, 03:44 PM
#4
Thread Starter
Member
Very Clever solutions, thanks guys.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|