Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 497
  • Last Modified:

algorithm to sort name alphabetically

hello,

i need an algorithm that sort lost of names alphabetically

thank you
0
MrFahad
Asked:
MrFahad
  • 2
  • 2
  • 2
  • +3
2 Solutions
 
DgleichCommented:
What language do you want? But the best would to use the ascii...
0
 
MrFahadAuthor Commented:
well i need it to be a pseudo code
0
 
HooKooDooKuCommented:
If you are programming in C/C++, the library likely contains a qsort function.  To utilize qsort, you supply the function an array of information to sort (I would suggest an array of pointers to the strings you want to sort because the array is sorted 'in place'), the size of the array, and a pointer to a function that qsort calls to compare two values from the array.  In this case, since your array is a set of pointers to strings, qsort will supply the function two pointers to strings.  In this callback function, simply cast the variables to pointer to strings and use strcmp() to determine how the two strings should compare.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
dbruntonCommented:
http://en.wikipedia.org/wiki/Sorting_algorithm

If you read the article there are links to all of the major sorting algorithms plus psuedo-code.
0
 
MrFahadAuthor Commented:
what if i want it in ascii like Dgleich mentioned
0
 
dbruntonCommented:
ascii is not a programming language.

ascii is text.  pseudo codes are in text (ascii).  Try the link I supplied.
0
 
t0t0Commented:
The bubble sort has to be the easiest to visualise and explain.

Basically, you scan your list of names say from left to right, comparing two adjacent names. If they are not in sort order, then swap them around. Continue doing this till you get to end of the list. Repeat this process until there are no swaps during a complete scan.

This is the design (assumes first element of list starts at '1'):

do
   set flag = false
   set index = 1
   do
      if list[index] > list[index + 1] then
         set tmp = list[index]
         set list[index] = list[index + 1]
         set list[index + 1] = tmp
         set flag = true
      end if
      increment index
   loop until index = size of list - 1
loop until flag = false
0
 
aikimarkCommented:
@MrFahad,

What is the context for this question?  For instance:
1. Is this a homework assignment?
2. Where does this list of names reside? (paper, electronic document, web page, txt file, etc.)
3. What is the run-time environment for this solution?
4. What software tools do you have at your disposal? (you might not need an algorithm if you have a tool that will do this sort for you)
5. What is your level of programming knowledge and skills?
0
 
t0t0Commented:
MrFahad

Was my comment (ID: 24073702) helpful to you? Do you need further assistance?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now