#ifndef MYLISTT #define MYLISTT #include #include template struct MyNode { T data; MyNode * next; }; template class MyListT { public: MyListT(){ head = nullptr; } // I don't want these functions avaialable so I will delete them. MyListT(const MyListT & t) = delete; MyListT & operator =(const MyListT & t) = delete; ~MyListT(); int Size(void) const { return nodeCount; } T Data(int i)const; void Insert(T d); private: MyNode * head = nullptr; int nodeCount = 0; }; template MyListT::~MyListT(){ MyNode * tmp{head}; while (tmp != nullptr) { head = tmp->next; delete tmp; tmp = head; } } template void MyListT::Insert(T d){ MyNode * tmp = new MyNode{d,head}; head = tmp; nodeCount ++; } template T MyListT::Data(int i) const { T rv{}; MyNode * tmp{head}; int j{0}; while (j < i and tmp!= nullptr) { tmp = tmp->next; j++; } if (tmp != nullptr) { rv = tmp->data; } return rv; } template void PrintList(MyListT & list) { int i; T data; std::cout << "The list size is " << list.Size() << std::endl; for(i = 0; i < list.Size(); i++) { data = list.Data(i); std::cout << "\tlist[" << i << "] = " << data << std::endl; } return; } #endif