Thread: how to sort an array

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    4

    how to sort an array

    I need to sort an array of strings alphabetically in c++ and I have no idea how to do this...

    I would prefer to do this without pointers or qsort or std::sort

    Thanks,

    Dustin

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    85
    you could try this:


    void SelectionSort(apvector<apstring>&v){
    n=v.length();

    while(n>1){
    //find largest element
    for(iMax=0, i=1; i<n; i++)
    if(v[i]>v[iMax])
    iMax=i;

    //swap
    temp=v[n-1];
    v[n-1]=v[iMax];
    v[iMax]=temp;
    }
    }

  3. #3
    Unregistered
    Guest
    convert the strings to all lower case or all upper case unless you feel A is different from a. Then use strcmp() to comare c_style strings, swapping the two strings if appropriate. If you are using STL style strings or apstrings or TStrings or CStrings then you can use a logical operator to do the comparison.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Insertion Sort on Array of Structs
    By n0r3gr3tz in forum C Programming
    Replies: 3
    Last Post: 04-01-2008, 08:28 AM
  2. Using unix command line to sort random array
    By lostmyshadow in forum C Programming
    Replies: 4
    Last Post: 12-11-2007, 07:14 PM
  3. New Sort an Array of Classes
    By ajpeters in forum C++ Programming
    Replies: 11
    Last Post: 09-06-2005, 06:23 PM
  4. how to sort out an array?
    By Chobo_C++ in forum C++ Programming
    Replies: 1
    Last Post: 03-08-2004, 05:33 PM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM