Solved

algorithm to sort name alphabetically

Posted on 2009-04-01
10
457 Views
Last Modified: 2012-05-06
hello,

i need an algorithm that sort lost of names alphabetically

thank you
0
Comment
Question by:MrFahad
  • 2
  • 2
  • 2
  • +3
10 Comments
 
LVL 3

Expert Comment

by:Dgleich
ID: 24043976
What language do you want? But the best would to use the ascii...
0
 

Author Comment

by:MrFahad
ID: 24044060
well i need it to be a pseudo code
0
 
LVL 16

Expert Comment

by:HooKooDooKu
ID: 24044093
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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 48

Accepted Solution

by:
dbrunton earned 250 total points
ID: 24044476
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
 

Author Comment

by:MrFahad
ID: 24046116
what if i want it in ascii like Dgleich mentioned
0
 
LVL 48

Expert Comment

by:dbrunton
ID: 24047380
ascii is not a programming language.

ascii is text.  pseudo codes are in text (ascii).  Try the link I supplied.
0
 
LVL 16

Assisted Solution

by:t0t0
t0t0 earned 250 total points
ID: 24073702
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
 
LVL 45

Expert Comment

by:aikimark
ID: 24099210
@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
 
LVL 16

Expert Comment

by:t0t0
ID: 24136081
MrFahad

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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
python sqlite question 11 46
Not needed 13 109
Modify a small python script 19 108
Reccomended programming language for client-server applications 12 86
This is about my first experience with programming Arduino.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now