Alphabetical Sorting String Array HELP

Alphabetical Sorting String Array HELP

Page 1 of 1

2 Replies - 13242 Views - Last Post: 27 January 2009 - 05:37 PM Rate Topic: -----

#1 Nike_Unltd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 13-August 08

Alphabetical Sorting String Array HELP

Posted 27 January 2009 - 01:52 PM

Hello Dream in code experts =],

I have an string array of 10 elements called wordList which has this:
yamaha, jack, harry, zena, google, peter, bob, ken, dude, pokemon


as you can see they are not not in alphabetical order. my question is, how can i sort these!? :blink:

Is This A Good Question/Topic? 0
  • +

Replies To: Alphabetical Sorting String Array HELP

#2 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: Alphabetical Sorting String Array HELP

Posted 27 January 2009 - 02:01 PM

First you should decide on some sorting algorithm that you want to use. A simple sorting algorithm is Bubblesort. You can find an implementation of it in the snippets section or through wikipedia.

To compare two strings you can use the function strcmp, it takes 2 strings as parameters and uses a comparator method to decide which string is smaller/larger. You can find an explanation of the function here.. http://www.cplusplus...ing/strcmp.html

[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#3 buckrogers1965  Icon User is offline

  • New Member

Reputation: 9
  • View blog
  • Posts: 87
  • Joined: 23-January 09

Re: Alphabetical Sorting String Array HELP

Posted 27 January 2009 - 05:37 PM

There is a qsort() and bsearch() built into C. bsearch() only works on sorted data.

There is an example with strings.
http://www.engin.umd...400/c/sort.html

Here is one of my examples with ints:
http://linuxgazette....rs_example05c.c

About halfway down I have a brief explanation of a qsort() and bsearch():
http://linuxgazette....e39/rogers.html

I also discuss return values. The examples should help you learn hot to create the comparator function for your data.

This post has been edited by buckrogers1965: 27 January 2009 - 05:38 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1