Computers

posted by .

Sort an array of ten 30 character items into ascending order of surname. Each line contains a name in the form e.g. Mr J Smith, Dr John R Smith or John Smith. There are no field or record delimiters, qualifications, suffixes, double-barrelled names or similar complications. Define names and values for the items in the array, using any programming language you choose. Using low level string and record manipulation and not higher level functions such as SORT, either draw a flowchart to show how you would perform the sort, or write the program.

  • Computers -

    Most computer languages have a command that assigns a numerical value to a character variable, such as VAL($A) in Visual Basic.

    I used to assign such a problem as you stated and found the "bubble method" to be the easiest to use for most students.

    Assign your data into an array of 30 subscripted string variables.
    Assign the first string variable as $large.

    Set up a loop that runs from 1 to 30, or n, comparing each item to $large.
    if the item is less than or equal to VAL($large) keep going in the loop, if the item is greater then assign its value to $large. Keep track of where you found the largest with a variable.

    At the end of the first loop, the largest value,(the highest name in your alpha list) will be exchanged with the last entry, and that last entry will be placed in the position where $large was found.

    Repeat the loop from 1 to 29, or n-1, the second largest will now be in the second last position etc.

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. MATH

    According to an informal poll in Glenview, 1/3 of the men and 2/3 of the women saud they would vote for John Smith. On election day, one and a half times as many men as women voted. What fraction of the total vote, according to the …
  2. social studies

    An Li reached puberty at age 12, and John Smith retired at age 65. An Li's and John Smith's experiences are examples of: A. normative events. B. non-normative influences. C. critical periods. D. risk factors. I chose A. but now reading …
  3. Java

    in Java how do you create a method that will prompt the user to type in 10 votes to determine a winner in a two candidate election?
  4. Health information

    A surgeon performs elective surgery on Patrick John Smith. Smith later complains to his surgeon about pain resulting from the surgery. His surgeon dismisses his complaints as not credible and eventually withdraws from the case. Smith …
  5. math

    John and Smith went to a stationery shop. John bought 6 pens, 4 pencils and 3 erasers. Smith bought 3 pens, 8 pencils and 6 erasers and spent 20% more than John. What percentage money did John spend on pens?
  6. legal issues for working health care

    patty, a patient of dr. smith was injured by dr. smith's malpractice in 2010, she filed suit in may 2011. under a claim-made policy, an insurance company will be responsible for defending dr. smith if it's the company who insuring …
  7. health and legal

    A surgeon performs elective surgery on Patrick John Smith. Smith later complains to his surgeon about pain resulting from the surgery. His surgeon dismisses his complaints as not credible and eventually withdraws from the case. Smith …
  8. Human Growth

    An Li reached puberty at age 12, and John Smith retired at age 65. An Li’s and John Smith’s experiences are examples of: A. normative events. B. non-normtive influences C. critical periods D. risk factors Is B the correct answer
  9. Law and ethics

    A surgeon performs elective surgery on John Smith. Smith later complains to his surgeon about pain resulting from the surgery. His surgeon dismisses his complaints as not credible and eventually withdraws from the case. Smith is then …
  10. History

    Both William Bradford and John Smith helped found American colonies. How did their actions differ?

More Similar Questions