Professional Documents
Culture Documents
Given: 24/06/08
Due: 08/07/08
Before doing the exercise, please read very carefully the submission guidelines. If you
have any questions about the exercise, please refer to the FAQ page first. If your question
is not answered there send an email.
If the user enters invalid input your program should print "error" and main should return
the value -1.
The program:
• Reads an integer number, which tells how many numbers are in the array
• Reads an array of integers.
• Sorts the array.
• Prints the sorted array.
Assumptions:
o The function merges the left and right arrays into destArr.
Example:
Input: 10
10 9 8 7 6 5 4 3 2 1
Output: 1 2 3 4 5 6 7 8 9 10
Given a sorted array of elements and a query element, you compare the query against the
element in the middle of the array (marked in green). If they are the same then there is
nothing more to do. Otherwise, if the query is smaller than the element in the middle of
the array, then it must appear before it in the array. So you need to search in the left half
(marked in white). If it is bigger, then you need to search the right half (marked in
yellow).
You repeat this until, you find the element, or you can't divide the array no more.
The program:
• Reads an integer number, which tells how many numbers are in the array
• Reads the sorted array of integers.
• Reads an integer number, which will be the search query.
• Prints a message telling if the number appears in the array or not.
Assumptions:
Example:
Input: 13
10 15 23 26 28 31 33 36 42 49 57 101 437
57
Output: Found it
Input: 13
10 15 23 26 28 31 33 36 42 49 57 101 437
39