Computer Science Canada Binary Search help! |
Author: | bobbySmith [ Tue Mar 24, 2009 1:16 pm ] | ||
Post subject: | Binary Search help! | ||
I have this question where I don't know where to start ![]() Implement a template class SortedList as defined by the following skeleton:
You need to use binary search in InsertItem( ), DeleteItem( ) and RetrieveItem( ). No linear search is allowed. In your main routine, you should create two instances of this template class: one is for char and the other is for floating point number. You also need to read in data from two data files: char.dat and float.dat, which can be downloaded from cis 200 web site and are assumed to be in the current directory. Data in char.dat contains chars, which should be inserted into the char SortedList, while data in float.dat contains floating numbers, which should be inserted into the float SortedList. Note the you do not have any prior knowledge about how data values in char.dat and float.dat. You should write a subroutine, int numCharElement(ifstream &x), to determine the number of char elements in char.dat, and another subroutine, int numFloatElement(ifstream &x), to determine the number of float elements in float.dat. A typical example of char.dat is as follows: a t r B T P j e m d A typical example of float.dat is 5.5 6.2 7.1 8.0 9.0 10.0 1.0 2.0 3.3 4.4 |