Lexicographical order, assignment help


Save your time - order a paper!

Get your paper written from scratch within the tight deadline. Our service is a reliable solution to all your troubles. Place an order on any task and we will take care of it. You won’t have to worry about the quality and deadlines

Order Paper Now

Write the
program that asks the user to enter 10 names of cities (one name at a time) to
be stored in an array, sorts the resulting list of city
names lexicographically and displays the sorted list to the console.

Note: Lexicographical order is a
generalization of the way the alphabetical order of words is based on the
alphabetical order of their component letters. It is also known as dictionary

Hint: Comparing two words
lexicographically can be done by using “<” and “>” for C++ strings.


Original List: Paris, Washington DC, London, Tokyo, Madrid, Rio di Janeiro,
Brussels, Ankara, Rome, Amsterdam

applying the Lexicographical order, the list will be become:

Resulting List:Amsterdam, Ankara, Brussels, London, Madrid, Paris, Rio di
Janeiro, Rome, Tokyo, Washington DC

If the first
letters of the two cities are the same, you should compare the next ones.

Original List:Ankara, Amsterdam

Resulting List:Amsterdam, Ankara


You are
given the following source code to search for a number in an array


namespace std;

search(int sa, int list[ ], int size)

  bool notFound = true;

  int position = -1;

  int k = 0;

  while (k<size && notFound)


  if (list[k] == sa)

  {  notFound
= false;

  position = k;




  return position;



main( )


searchArg = 17; 

myList[10] = {16,14,54,23,8,12,17,36,11,22};


call Search to find the value’s position

= search(17,myList,10);

<< “Search key was found at index “ << pos << endl;

search function and the main method to search for a string value, entered by
the user,in a string array, instead of searching for an integer value in an
integer array.

This is the
string list to use for test:

List: Rome, Ankara, Brussels, London, Madrid, Paris, Rio di Janeiro, Tokyo,
Washington DC