#include <iostream>
#include <string>
#include <vector>
usingnamespace std;
template <typename T>
class Mlist
{
public:
Mlist();//creates the list
T front();//returns the front of the list
T last();//returns the end of the list
bool in(T x);//returns true if x is in the list and false otherwise
bool empty(); // returns true if the list is empty
void addfront(T entry);//add entry to the back of the list
void addend(T entry);//add entry to the back of the list
void addorder(T entry);//add entry to an ordered list
void removefront();//removes the front of the list
void removeend();//removes the back of the list
void remove(T n);//searches the list and removes the entry with value n
private:
vector<T> mlist;
void remove(typename vector<T>::iterator ix, T n);//uses an iterator and recursion to remove value n
void addorder(typename vector<T>::iterator ix, T n);//uses an iterator and recursion to add value n in an ordered list
}; // mlist
template <typename T>
Mlist<T>::Mlist()
{
}
template <typename T>
T Mlist<T>::front()
{
T x;
if(empty())
{
return x;
}
else
{
return *mlist.begin();
}
}
template <typename T>
T Mlist<T>::last()
{
T x;
if(empty())
{
return x;
}
else
{
return *(--mlist.end());
}
}
template <typename T>
bool Mlist<T>::in (T x)
{
for(int i = 0; i < mlist.size();)
{
if(mlist[i] ==x)
{
returntrue;
}
}
returnfalse;
}
template <typename T>
bool Mlist<T>::empty()
{
if(mlist.size() == 0)
{
returntrue;
}
else
{
returnfalse;
}
}
template <typename T>
void Mlist<T>:: addfront(T x)
{
if(this ->empty())
{
mlist.push_back(x);
}
else
{
mlist.insert(mlist.begin(),x);
}
}
template <typename T>
void Mlist<T>:: removefront()
{
if(!this ->empty())
{
mlist.erase(mlist.begin());
}
}
template <typename T>
void Mlist<T>:: removeend()
{
if(!this ->empty())
{
(--mlist.end());
}
}
template <typename T>
void Mlist<T>::addorder (T entry)
{
if(this ->empty())
{
addorder(mlist.begin(), entry);
}
else
{
mlist.push_back(entry);
}
}
template <typename T>
void Mlist<T>::remove(T n)
(typename vector <T>::iterator ix, T n)
{
if(ix==mlist.end())
{
return
}
if (*ix ==n)
{
mlist.erase(ix, n);
remove(ix);
}
else
{
remove(++ix, n);
}
}
int main()
{
Mlist<int> test1=Mlist<int>() ;
test1.addend(5);
test1.addend(7);
test1.addend(4);
test1.remove(7);
cout << test1.front()<< endl;
cout << test1.last()<< endl;
Mlist<string> test2= Mlist<string>() ;
test2.addend("John");
test2.addend("Paul");
test2.addend("Mary");
test2.addend("Kate");
test2.remove("Paul");
cout << test2.front()<< endl;
cout << test2.last()<< endl;
}
but now i get the error:
/tmp/cc54uecp.o: In function `main':
hw4.cpp:(.text+0x67): undefined reference to `Mlist<int>::remove(int)'
hw4.cpp:(.text+0x239): undefined reference to `Mlist<std::string>::remove(std::string)'
collect2: error: ld returned 1 exit status