algorithm - Logic challenge: sorting arrays alphabetically in C -


i'm new programming, learning c. i've been working @ problem week now, , can't seem logic straight. straight book i'm using:

build program uses array of strings store following names:

  • "florida"
  • "oregon"
  • "califoria"
  • "georgia"

using preceding array of strings, write own sort() function display each state's name in alphabetical order using strcmp() function.

so, let's have:

char *statesarray[4] = {"florida", "oregon", "california", "georgia"};  

should nested loops, strcmp(string[x], string[y])...? i've hacked , hacked away. can't wrap head around algorithm required solve efficiently. appreciated!!!

yes, can sort using nested loops. after understand how strcmp() works should straight forward:

strcmp(char *string1, char *string2)

  • if return value < 0 indicates string1 less string2

  • if return value > 0 indicates string2 less string1

  • if return value = 0 indicates string1 equal string2

you can choose of sorting methods once point

this site has ton of great graphical examples of various sorts being performed , includes pseudo code given algorithms.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -