#ifndef MYLISTT #define MYLISTT #include #include template struct MyNode { T data; MyNode * next; }; template class MyListT { public: MyListT():head(nullptr){} MyListT(const MyListT & t) = delete; MyListT & operator =(const MyListT & t) = delete; ~MyListT() { MyNode * tmp; tmp = head; while (tmp != nullptr) { head = tmp->next; delete tmp; tmp = head; } } void Foo(void) { std::vector d; d.push_bk(head->data); } int Size(void) const { return nodeCount; } T Data(int i) const { T rv{}; MyNode * tmp; int j = 0; tmp = head; while (j < i and tmp!= nullptr) { tmp = tmp->next; j++; } if (tmp != nullptr) { rv = tmp->data; } return rv; } void Insert(T d) { MyNode * tmp = new MyNode{d,head}; head = tmp; nodeCount ++; } private: MyNode * head = nullptr; int nodeCount = 0; }; 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