How do you sort in C# programmatically.
Meaning not to use the properties window to set sort to true.
Meaning not to use Array.Sort feature either.
This is actually a sort array coded programmatically at runtime.
Thanks i appreciate for your help.
8 2998 Plater 7,872
Recognized Expert Expert
You want to create your own sorting implementation? There's going to be thosaunds of websites that detail the algorithms. Try googling for some.
I did and got this site. This site actually stated that I can get help in programming. I just needed some help. So here I am asking. Can anyone in this forum help me in sorting in C#.
Thanks.
cloud255 427
Recognized Expert Contributor
Sorting is based on algorithms, its not really language specific. Several of the .NET collections have sorting methods already exposed. For us to help you with a sorting algorithm you need to be more specific. What datastructure are you trying to sort? Is there any specific sorting technique you would like to use?
Have a look at Insertion sort, Selection sort, Bubble sort and Quick sort These are all fairly well known and easy to implement algorithms.
Plater 7,872
Recognized Expert Expert
I didn't mean for it to sound like I was giving you the "runaround".
Your question wasn't very clear. You never actually said "I am trying to implement my own sorting functions, but am not sure how to start"
Cloud went a step further then me and did some leg work for you, finding links to common sorting algorithms, which is what I was trying to get at by suggesting to google it.
We will not write your sorting function for you, but we can help you if you're stuck in your implementation.
Hello Cloud and Plater,
My bad I forgot to say that.
I am trying to have the contents of a textbox displayed in the listbox sorted by lastname and alphabetically. I know about the feature in properties but they want it to be done programmatically. I am not sure how to go about it. But I know its an array that I need to sort. The feature in the .Net Framework is Array.Sort. Now in order to be valid it has to be done programmatically.
I also previously posted my entire code for the AddressBook array. I cannot get it to work accordingly.
Can you help me.
Plater 7,872
Recognized Expert Expert
Well i would consider Array.Sort() to be programmatically, chances are pretty good that's what was meant. Just not having to sort it by hand.
If you want to use array.sort(), you will probably have to deal with either ICompare interface or the IComparable interface (depending on how you want to tackle it) The basic idea is to provide a function that takes in two different objects of the same type and you return either a -1,0,1 to say if object A comes before, is the same, or after object b.
You would have access to all of A and Bs values, so you can compare by last name then sort by first name.
Is this a schoolwork assignment? If so, read up on the links that cloud provided, and implement one of those algorithms.
If not, then the Array.Sort() method is perfect. If you need custom sorting, I prefer to use the IComparable interface.
Hello inSertAlias,
Yes I agree I wish I could use the Array.Sort is much better and easier.
I have to study a little more on the sort you mentioned that Cloud pointed out for me. Ok thanks all.
I'll try my best to do this final assignment. Been working on it for a week and is due next Tuesday but thanks all and I understand. Thanks
Regards,
Desi Bravo
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: dont bother |
last post by:
This is really driving me crazy.
I have a dictionary feature_vectors{}. I try to sort
its keys using
#apply sorting on feature_vectors
sorted_feature_vector=feature_vectors.keys()...
|
by: ck388 |
last post by:
For some reason when I enable the callback feature of the gridview I
still get a page refresh, that is it seems like there is a postback
that occurs, not a callback which is just supposed to update...
|
by: Federico G. Babelis |
last post by:
Hi All:
I have this line of code, but the syntax check in VB.NET 2003 and also in
VB.NET 2005 Beta 2 shows as unknown:
Dim local4 As Byte
Fixed(local4 = AddressOf dest(offset))
...
|
by: Owen T. Soroke |
last post by:
Using VB.NET
I have a ListView with several columns.
Two columns contain integer values, while the remaining contain string
values.
I am confused as to how I would provide functionality to...
|
by: Sjaakie |
last post by:
Hi,
I'm, what it turns out to be, fooling around with 3-tier design.
At several websites people get really enthusiastic about using custom
dataobjects instead of datasets/-tables.
While trying to...
| |
by: Ambica Jain |
last post by:
Hi,
I want custom sorting on some of the columns in the datagrid. And i am able
to do the same by overriding MouseDown event. However, i need to rebind my
datatable to reflect the changes in...
|
by: Kamal |
last post by:
Hello all,
I have a very simple html table with collapsible rows and sorting
capabilities. The collapsible row is hidden with css rule
(display:none). When one clicks in the left of the...
|
by: KevinADC |
last post by:
Introduction
In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar...
|
by: lemlimlee |
last post by:
hello,
this is the task i need to do:
For this task, you are to develop a Java program that allows a user to search or sort an array of numbers using an algorithm that the user chooses. The...
|
by: jrod11 |
last post by:
hi,
I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |