Lab 10  Searching and Sorting

Evaluation Scheme: TAs will verify solution and tick the programs
No submission required.

Part 1


int sort (int *A, int size);
 
   Implement a function that sorts an integer array of given size using the bubble sort algorithm.
   The return value  indicates the no. of swaps. 

   In your main, read the array from a file, sort it using this function,
   and output the result in another file.



int bsearch (int *A, int size, int element, int &position);

   Search the element in the sorted array of given size using binary search algorithm by
   reducing the search space in every iteration.
 
   Position: returns the index where the element is found. It is -1 if the element is not found
   Return value: no. of comparisons made.




Part 2:

Having done the above two functions, convert the first one to work on string arrays:

int sort (string *A, int size);



Try it out with the sample files that you used in the previous assignment to generated
a sorted list of words used by the text. If you could remove duplicates, you will
obtain a dictionary.

For comparing s1 and s2, you can use the return value of the comparison operator
 s1.compare(s2).


Deadline: 10:30 pm