bubble sort array of strings

This is a discussion on bubble sort array of strings within the C Programming forums, part of the General Programming Boards category; how do you sort an array of strings into alphabetical order using bubble sort. do you use strcpy() to swop ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    17

    Question bubble sort array of strings

    how do you sort an array of strings into alphabetical order using bubble sort.

    do you use strcpy() to swop the strings around.

  2. #2
    kdt
    kdt is offline
    Registered User
    Join Date
    Mar 2002
    Posts
    9
    char *str[5]={"string","sorting","with","bubble","sort"};
    char *tmp;

    for(i=1;i<5;++i)
    for(j=4;j>=i;--j) if (strcmp(str[j-1],str[j])>0){
    tmp=str[j-1];
    str[j-1]=str[j];
    str[j]=tmp;
    }
    after sorting:
    str[1] --> bubble
    str[2] --> sort
    str[3] --> sorting
    str[4] --> string
    str[5] --> with

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2005, 03:00 PM
  2. bubble sort
    By angelic79 in forum C Programming
    Replies: 2
    Last Post: 10-19-2004, 12:00 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. the bubble sort doesn't work help
    By Matt in forum C Programming
    Replies: 2
    Last Post: 12-13-2001, 05:14 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM

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