Question
Implement a class SortedList as defined by the following skeleton: #define MAX_ITEMS 10 typedef float ItemType; class SortedList { private: int length; ItemType values[MAX_ITEMS]; int
Implement a class SortedList as defined by the following skeleton:
#define MAX_ITEMS 10
typedef float 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
};
Requirement: You should use binary search in InsertItem( ), DeleteItem( ) and RetrieveItem( ).
In your main routine, the following tasks are required to complete:
Task 1: Create one instance of this class. You also need to read in data from one data file: float.dat, which contains the following numbers:
35.5
26.2
67.1
18.0
9.0
10.0
31.0
62.0
13.3
4.4
Data in float.dat contains floating numbers, which should be inserted into the object of SortedList. Note that you do not have any prior knowledge about data values in float.dat, but we assume that there are 10 elements in the data file.
Task 2: Use GetNextItem( ) to print out all the elements in the list in sorted sequence on computer screen.
Task 3: Use GetNextItem( ) to output all the elements in the list in sorted sequence onto a data file, output.dat.
Task 4: Design your test cases to demonstrate InsertItem( ), DeleteItem( ) and RetrieveItem( ) are working as expected. A binary search should be implemented in these three functions.
Task 5: What is the time complexity of linear and binary searches ?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started