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 Atint index; Return the element at index
int FindTheType value; Return index of first occurrence
of value or if not found
void InsertTheType value; Insert value at its sorted index
bool RemoveTheType 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::Atint index
Type your code here.
template
int OrderedList::FindTheType value
Type your code here.
template
void OrderedList::InsertTheType newItem
unsigned int j; Vector size is unsigned int
unsigned int k; Vector size is unsigned int
if listsize
list.pushbacknewItem;
return;
j ;
while j list.size && newItem list.atj
j;
list.resizelistsize;
Now all items after index j are newItem
if j list.size
If newItem is last element, just add at end of list
list.pushbacknewItem;
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; k j; k
list.atk list.atk;
finally, insert newItem
list.atk newItem;
NOTE: Uses Find
template
bool OrderedList::RemoveTheType oldItem
unsigned int j;
int indx FindoldItem;
Type your code here.
template
void OrderedList::Print
for int j ; j Size; j
cout list.atj;
if j Size
cout ; No end line after last element
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
