Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 08-30-2005, 01:10 AM   #1 (permalink)
bradleyc
Registered User
 
Join Date: Aug 2005
Posts: 17
bradleyc is on a distinguished road
Alphabetical Sort?

How would i go about creating an Alphabetical Sort?
bradleyc is offline   Reply With Quote
Old 08-30-2005, 02:01 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
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.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 08-30-2005, 02:06 AM   #3 (permalink)
bradleyc
Registered User
 
Join Date: Aug 2005
Posts: 17
bradleyc is on a distinguished road
Oh my apologises that would be in C++
bradleyc is offline   Reply With Quote
Old 08-30-2005, 06:11 AM   #4 (permalink)
Locutus
Registered User
 
Join Date: Aug 2005
Posts: 20
Locutus is on a distinguished road
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?
Locutus is offline   Reply With Quote
Old 08-30-2005, 06:13 AM   #5 (permalink)
bradleyc
Registered User
 
Join Date: Aug 2005
Posts: 17
bradleyc is on a distinguished road
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 ...
bradleyc is offline   Reply With Quote
Old 08-30-2005, 07:58 AM   #6 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
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".
__________________
Valmont is offline   Reply With Quote
Old 08-31-2005, 02:36 PM   #7 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
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?
Salchester is offline   Reply With Quote
Old 08-31-2005, 03:51 PM   #8 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
Here are a few examples, qsort; quick sort; Numerical Recipes; STL sort, C++ vectors; STL sort, C arrays; Bubble sort theory, theory in string sorting.

I'm sure google can come up with more examples if it is needed...
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 08-31-2005, 05:46 PM   #9 (permalink)
toe_cutter
Code Monkey
 
Join Date: Aug 2002
Location: Boston, MA
Posts: 79
toe_cutter is on a distinguished road
Send a message via ICQ to toe_cutter Send a message via AIM to toe_cutter Send a message via Yahoo to toe_cutter
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.
__________________
toe_cutter is offline   Reply With Quote
Old 08-31-2005, 06:48 PM   #10 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
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.
__________________
Valmont is offline   Reply With Quote
Old 09-01-2005, 02:17 AM   #11 (permalink)
Locutus
Registered User
 
Join Date: Aug 2005
Posts: 20
Locutus is on a distinguished road
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.
Locutus is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sort of same as gamehead Androto Standard C, C++ 4 11-18-2004 04:09 PM
sorting objects arrays by object properties sde Java 28 08-05-2004 06:51 AM
Need an alphabetic sort algorithm SkittlesAreYum Java 4 05-09-2003 12:02 AM
dynamic allocation..urgent help needed!!! kashif Standard C, C++ 4 04-21-2003 09:50 AM
sort arrays Apodysophilia Java 9 04-04-2003 07:18 AM


All times are GMT -8. The time now is 06:01 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting