Binary Search help!
Author |
Message |
bobbySmith
|
Posted: Tue Mar 24, 2009 1:16 pm Post subject: Binary Search help! |
|
|
I have this question where I don't know where to start If someone can guide me what to do, I would greatly appreciate it.
Implement a template class SortedList as defined by the following skeleton:
c++: |
#define MAX_ITEMS 20
template<class ItemType>
class SortedList
{
private:
int length;
ItemType values[MAX_ITEMS];
int currentPos;
public:
SortedList( ); // default constructor: lenght=0, currentPos=-1
void MakeEmpty; // let length=0
void InsertItem(ItemType x); // insert x into the list
void DeleteItem(ItemType x); // delete x from the list
bool IsFull( ); // test if the list is full
int Lengthls( ); // return length
void RetrieveItem(ItemType &x, bool &found); // retrieve x from the list, the
// boolean result is stored in found
void ResetList( ); // currentPos=-1
void GetNextItem(ItemType &x); // get the next element from the list with
// respect to the currentPos
};
|
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 |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
|
|