Alphabetical Sort

This is a discussion on Alphabetical Sort within the C Programming forums, part of the General Programming Boards category; I read in a list of commands from a file into a two dimensional array. I now need to sort ...

  1. #1
    steve8820
    Guest

    Question Alphabetical Sort

    I read in a list of commands from a file into a two dimensional array. I now need to sort these commands in alphabetical order. I was wondering if anyone knows where I can get a alphabetical sorting algorithm for C. If anyone can point me in the right direction it would be great.

    Thanks,

    Steve

  2. #2
    Unregistered
    Guest
    Search this board for recent examples of the use of qsort (which is a standard function in stdlib.h)

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    16
    How about writing your own? Wouldn't THAT be a novel idea?
    You could try a simple bubble sort on the array by testing the first character of each element.

    e.g.

    Code:
    char array[4][4];
    char *tmp;
    int i;
    
    for(i = 0; i < 4; i++) {
      if(array[i][0] > array[i + 1][0]) {
        tmp = array[i];
        array[i] = array[i + 1];
        array[i + 1] = tmp;
      }
    }
    
    (This code probably doesn't work, it's just an example.
    You should be able to figure it out from this.)
    The box said 'Windows NT or better', so I installed Linux.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Straight Insertion Sort function problem
    By StaticKyle in forum C++ Programming
    Replies: 6
    Last Post: 05-12-2008, 04:03 AM
  2. threaded merge sort
    By AusTex in forum Linux Programming
    Replies: 4
    Last Post: 05-04-2005, 04:03 AM
  3. Replies: 2
    Last Post: 02-07-2003, 11:09 AM
  4. Shell Sort vs Heap Sort vs Quick Sort
    By mackol in forum C Programming
    Replies: 6
    Last Post: 11-22-2002, 07:05 PM
  5. Alphabetical sort using STRCMP()
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 03-27-2002, 06:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21