Thread: Names into Alphabetic Order

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    9

    Names into Alphabetic Order

    Lo all
    I am wanting to sort a list of names into alphabetic order, however, I don't want to use a 2d array. I can get it to work using a 2d array and qsort, but how would I go about using an array of pointers to char and adjusting the pointers rather than copying the strings?

    If ne1 can give me ne tips to get me on the right lines it will be greatly appreciated.

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    98
    I would create a linked list of chars, then perform a bubble sort on the list.

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    9
    Don't want to use bubble sort

  4. #4
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    Have you done bubble sort try that with strings..

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
     char *ch[] = {"Welcome ","to ","C"};
     int cnt=0;
    
     while ( cnt < 3 ){
           printf("%s", ch[cnt] );
     }     cnt++;
    
    
          system("PAUSE");
          return 0;
    }
    Implementation of cha *[] .....SO you can use bubble sort or qsort to sort them out remeber you dont compare strings with a == ...use your strcmp() function which resides in your string.h for comparison between 2 strings ..
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    157
    i think you best use a tree for something alphabetical. it's easiest and definitely fastest.

  6. #6
    Registered User
    Join Date
    Oct 2002
    Posts
    9

    Thumbs up

    Thanks for all the help people, thoroughly appreciated

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. names in alphabetical order?
    By n3cr0_l0rd in forum C Programming
    Replies: 21
    Last Post: 02-06-2009, 08:59 PM
  2. Laplace Expansion
    By Leojeen in forum C Programming
    Replies: 7
    Last Post: 10-28-2008, 11:26 PM
  3. Replies: 22
    Last Post: 05-28-2008, 05:27 PM
  4. How do you order your game code?
    By Queatrix in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 02-05-2006, 06:26 PM
  5. Help me sort the names in alpha order.
    By cazil in forum C++ Programming
    Replies: 2
    Last Post: 02-04-2002, 02:30 PM