#include <iostream>
#include <list>
using namespace std;

template<class T>
class MyList {
private:
    list<T> m_list;
public:
    void addToBack(const T&);
    void addInMiddle(const T&);
    void printList();
};

template<class T>
void MyList<T>::addToBack(const T& x) {
    m_list.push_back(x);
}

template<class T>
void MyList<T>::addInMiddle(const T& x) {

    typename list<T>::iterator it = m_list.begin();

    int location = m_list.size() / 2;     //where we want to insert the new element
    for (int i = 0; i < location; i++) {
        it++;
    }

    m_list.insert(it, x);
}

template<class T>
void MyList<T>::printList() {
	for(const auto& elem : m_list) {
		cout << elem << " ";
	}
	cout << endl;
}

int main()
{
    MyList<int> list1;
    list1.addToBack(1);
    list1.addToBack(2);
    list1.addToBack(3);
    list1.addToBack(4);
    list1.addInMiddle(5);
    list1.printList();
    return 0;
}