Question: #ifndef H _ unorderedArrayListType #define H _ unorderedArrayListType #include arrayListType.h template class unorderedArrayListType: public arrayListType { public: void insertAt ( int location, const elemType&

#ifndef H_unorderedArrayListType
#define H_unorderedArrayListType
#include "arrayListType.h"
template
class unorderedArrayListType: public arrayListType
{
public:
void insertAt(int location, const elemType& insertItem);
void insertEnd(const elemType& insertItem);
void replaceAt(int location, const elemType& repItem);
int seqSearch(const elemType& searchItem) const;
void remove(const elemType& removeItem);
unorderedArrayListType(int size =100);
//Constructor
};
template
void unorderedArrayListType::insertEnd
(const elemType& insertItem)
{
if (this->length >= this->maxSize)//the list is full
cout << "Cannot insert in a full list." << endl;
else
{
this->list[this->length]= insertItem; //insert the item at the end
this->length++; //increment the length
}
}//end insertEnd
template
int unorderedArrayListType::seqSearch
(const elemType& searchItem) const
{
int loc;
bool found = false;
for (loc =0; loc < this->length; loc++)
if (this->list[loc]== searchItem)
{
found = true;
break;
}
if (found)
return loc;
else
return -1;
}//end seqSearch
template
void unorderedArrayListType::remove
(const elemType& removeItem)
{
int loc;
if (this->length ==0)
cout << "Cannot delete from an empty list." << endl;
else
{
loc = seqSearch(removeItem);
if (loc !=-1)
this->removeAt(loc);
else
cout << "The item to be deleted is not in the list."
<< endl;
}
}//end remove
template
void unorderedArrayListType::replaceAt(int location,
const elemType& repItem)
{
if (location <0|| location >= this->length)
cout << "The location of the item to be "
<< "replaced is out of range." << endl;
else
this->list[location]= repItem;
}//end replaceAt
template
void unorderedArrayListType::insertAt(int location, const elemType& insertItem){
if (location <0|| location >= this->maxSize){
std::cout << "The position of the item to be inserted is out of range." << std::endl;
} else if (this->length >= this->maxSize){
std::cout << "Cannot insert into a full list." << std::endl;
} else {
for (int i = this->length; i > location; i--){
this->list[i]= this->list[i -1]; // Shift elements right
}
this->list[location]= insertItem;
this->length++; // Increment list size
}
}
template
unorderedArrayListType::
unorderedArrayListType(int size)
: arrayListType(size)
{
}//end constructor
#endif // H_unorderedArrayListType

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!