Question: #include / * - - - - - - - - - End OrderedList function implementations - - - - - - - - -

#include /*--------- End OrderedList function implementations -----------*/
// Demonstration of functions
int main(){
OrderedList
#include
#include
using namespace std;
/*----------- Template class OrderedList declaration -----------*/
template class OrderedList {
public:
int Size(); // Number of elements in the list
TheType At(int index); // Return the element at index
int Find(TheType value); // Return index of first occurrence
// of value or -1 if not found
void Insert(TheType value); // Insert value at its sorted index
bool Remove(TheType value); // Find the first occurrence of value
// and remove the value; true if success
void Print();
private:
vector list; // Elements are stored in list
};
/*----------- OrderedList function implementations ------------*/
template
int OrderedList::Size(){
/* Type your code here. */
}
template
TheType OrderedList::At(int index){
/* Type your code here. */
}
template
int OrderedList::Find(TheType value){
/* Type your code here. */
}
template
void OrderedList::Insert(TheType newItem){
unsigned int j; // Vector size is unsigned int
unsigned int k; // Vector size is unsigned int
if (list.size()==0){
list.push_back(newItem);
return;
}
j =0;
while (j list.size() && newItem > list.at(j)){
++j;
}
list.resize(list.size()+1);
// Now all items after index j are >= newItem
if (j == list.size()){
// If newItem is > last element, just add at end of list
list.push_back(newItem);
} else {
// Now move backwards from the end of the list copying elements to
// the next higher position; stop at j, where newItem will go
for (k = list.size()-1; k > j; --k){
list.at(k)= list.at(k-1);
}
// finally, insert newItem
list.at(k)= newItem;
}
}
// NOTE: Uses Find()
template
bool OrderedList::Remove(TheType oldItem){
unsigned int j;
int indx = Find(oldItem);
/* Type your code here. */
}
template
void OrderedList::Print(){
for (int j =0; j Size(); ++j){
cout list.at(j);
if (j Size()){
cout ""; // No end line after last element
}
}
}
#include / * - - - - - - - - - End OrderedList

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!