#include <iostream>
#include <vector>
#include <string>
usingnamespace std;
template<class T>
class mlist
{
public:
mlist();//creates the list
T front();//returns the front of the list
T end();//returns the end of the list and moves every entry up one position;
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>
mlist<T> :: front()
{
return *mlist.begin();
}
template <typename T>
mlist<T> :: end()
{
return(*--mlist.end());
}
template <typename T>
bool mlist<T> in (Tx)
{
for(int i = 0; i<mlist.size(); i++)
{
if(mlist [i] == x)
{
returntrue;
}
}
returnfalse;
}
bool mlist<T> in (Tx)
{
typename vector <T> :: iterator it;
for (it = mlist.begin; it! = mlist.end(); it++)
{
if (* it == 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 entry)
{
mlist.insert (mlist.begin(), entry);
}
template <typename T>
void mlist<T> :: addend (T entry)
{
mlist.push_back(entry);
}
template <typename T>
void mlist<T> :: remove front()
{
mlist.erase (mlist.begin());
}
template <typename T>
void mlist<T> :: remove end()
{
mlist.erase (--mlist.end());
}
template <typename T>
void mlist<T> :: remove (Tn)
{
remove (mlist.begin(), n);
}
template <typename T>
void mlist<T> :: remove (typename vector <T> :: iterator ix, Tn)
{
if (ix == mlist.end())
{
return;
}
if (*ix == n)
{
mlist.erase (ix);
return;
}
remove (++ ix, n);
}
template <typename T>
void mlist<T> :: addorder (T entry)
{
addorder (mlist.begin(), entry)
}
{
if (ix == mlist.end())
{
mlist.insert(ix, n);
return;
}
if (n <= *ix)
{
mlist.insert(ix, n);
return;
}
addorder(++ix, n);
}
int main()
{
mlist<int> test1=mlist<int>() ;
test1.add(5);
test1.add(7);
test1.add(4);
test1.remove(7);
cout << test1.front()<< endl;
cout << test1.back()<< endl;
mlist<string> test2= mlist<string>() ;
test2.add("John");
test2.add("Paul");
test2.add("Mary");
test2.add("Kate");
test2.remove("Paul");
cout << test2.front()<< endl;
cout << test2.back()<< endl;
}
|32|error: need 'typename' before 'mlist<T>::T' because 'mlist<T>' is a dependent scope|
|38|error: need 'typename' before 'mlist<T>::T' because 'mlist<T>' is a dependent scope|