Thread: Sorting...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    31

    Sorting...

    Can someone help me with sorting lastnames alphabetically?

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    I'm sure someone can.


    But for starters, why don't you do some sorting research online? Or come up with an algorithm and ask us how you can improve it?

    To help you save time, look up: heap sort, bubble sort, quicksort.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    31
    Those sorts messes up the index ( sLastname[index] ) I need the original index to display the information about that peson.

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    You want to sort objects, not strings. The information moves along with the object.

    I posted a complete example code the last time you asked this question (http://cboard.cprogramming.com/showt...threadid=40407). That code will take objects of a certain type and sort them, using the builtin C++ vector and sorting algorithms.

  5. #5
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    You can have multiple arrays that are connected. For example, say you have two sorting criteria, then you could have the following:

    Code:
    class data
    { // Whatever ... 
    };
    
    struct c1
    {
       int value;
       data* ptr;
    };
    
    struct c2
    {
       int value;
       data* ptr;
    };
    When you create each instance of c1 and c2, you give it a pointer to a data object (which are stored in their own array). The values for c1 and c2 are also stored in their own separate arrays, but even after being sorted, they still point to the same data.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 02:14 AM
  2. sorting structure members using pointers
    By robstr12 in forum C Programming
    Replies: 5
    Last Post: 07-25-2005, 05:50 PM
  3. Sorting words with a fast, effincient sorting method
    By Unregistered in forum C++ Programming
    Replies: 19
    Last Post: 07-12-2002, 04:21 PM
  4. Still Needing Help : selection sorting
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 10-14-2001, 08:41 PM
  5. selection sorting
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 10-13-2001, 08:05 PM