|
 |
|
 |
08-30-2005, 12:10 AM
|
#1 (permalink)
|
|
Registered User
Join Date: Aug 2005
Posts: 17
|
Alphabetical Sort?
How would i go about creating an Alphabetical Sort?
|
|
|
08-30-2005, 01:01 AM
|
#2 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
|
Since you're not specific on if it's C or C++ or if it's supposed to take char* or string or whatnot, I'll advise you to look at strcmp() and work that into your sorting algorithm, that is, if it's supposed to be in C.
|
|
|
08-30-2005, 01:06 AM
|
#3 (permalink)
|
|
Registered User
Join Date: Aug 2005
Posts: 17
|
Oh my apologises that would be in C++
|
|
|
08-30-2005, 05:11 AM
|
#4 (permalink)
|
|
Registered User
Join Date: Aug 2005
Posts: 20
|
Quote:
|
Originally Posted by bradleyc
How would i go about creating an Alphabetical Sort?
|
Do you want to know how to write a sorting algorithm, or do you just want to sort stuff?
|
|
|
08-30-2005, 05:13 AM
|
#5 (permalink)
|
|
Registered User
Join Date: Aug 2005
Posts: 17
|
Quote:
|
Originally Posted by Locutus
Do you want to know how to write a sorting algorithm, or do you just want to sort stuff?
|
Id probably have to say ... just want to sort stuff ...

|
|
|
08-30-2005, 06:58 AM
|
#6 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
|
Bradly... be more serious young lad. C++ isn't easy. Learn to make your coding life easy yet correct. Start with communication. I keep hammering on that to everybody. This isn't a "l33t Gaming Forum".
__________________
|
|
|
08-31-2005, 01:36 PM
|
#7 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
Locutus,
Out of interest how you would create a sorting alorithm?
Many Thanks
__________________
Many Thanks, in advance!
Salchester.
The Future Is Here - Are You Ready?
|
|
|
08-31-2005, 04:46 PM
|
#9 (permalink)
|
|
Code Monkey
Join Date: Aug 2002
Location: Boston, MA
Posts: 79
|
Quote:
|
Originally Posted by Salchester
Locutus,
Out of interest how you would create a sorting alorithm?
Many Thanks
|
Not to sound like a jerk, but most programming books have the basic sorting algorithms in them. Honestly just check the index at the back of the book.
__________________
|
|
|
08-31-2005, 05:48 PM
|
#10 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
|
In general, the type that is being compared needs to be able to be compared with the same type. For example if you would like to sort integers then at one moment a comparison is needed like:
Code:
if( FirstInt < SecondInt)
{
//Do stuff.
}
This snippet implies that the type of FirstInt and SecondInt can be compared with eachother.
The class or type they represent needs to be a comparable class or type.
Suppose one wants to sort humans. Such a definition doesn't make much sense. The next refinement is that I may want to sort people by some sort of property they have. This looks reasonable. The whole trick is now to define a class CHuman that is comparable. The same goes for cars, houses, services and whatever you can think of.
Conclusion:
Study the ways of making comparable classes.
__________________
|
|
|
09-01-2005, 01:17 AM
|
#11 (permalink)
|
|
Registered User
Join Date: Aug 2005
Posts: 20
|
Well, yeah. Finding a tutorial on something like Quick Sort or Bubble Sort shouldn't be too hard. The basis for pretty much any sorting algorithm comes down to comparing an item to another and changing the order of the items based on that.
As for sorting stuff, this is probably where Valmont is going, but the standard library contains functions for that. It would help if we had a little more information, like what you're trying to sort, why you're doing it this way, what code you've got so far, etc.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 03:50 PM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|