algorithm to sort name alphabetically

Posted on 2009-04-01
Medium Priority
Last Modified: 2012-05-06

i need an algorithm that sort lost of names alphabetically

thank you
Question by:MrFahad
  • 2
  • 2
  • 2
  • +3

Expert Comment

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

Author Comment

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

Expert Comment

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.
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

LVL 50

Accepted Solution

dbrunton earned 1000 total points
ID: 24044476

If you read the article there are links to all of the major sorting algorithms plus psuedo-code.

Author Comment

ID: 24046116
what if i want it in ascii like Dgleich mentioned
LVL 50

Expert Comment

ID: 24047380
ascii is not a programming language.

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

Assisted Solution

t0t0 earned 1000 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'):

   set flag = false
   set index = 1
      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
LVL 47

Expert Comment

ID: 24099210

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?
LVL 16

Expert Comment

ID: 24136081

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

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
Why WooCommerce is one of the majorly favored choices when it comes to having an eCommerce store. This article will acquaint you with some reasons that I believe make it one of the best eCommerce platforms available.
Introduction to Processes
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

586 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