#include using namespace std; template class Node { public: int Value; Node *Next; Node(T value) : Value(value), Next(NULL) { } }; template void PrintNode(Node *node) { while (node != NULL) { cout << node->Value << " - > "; node = node->Next; } cout << "NULL" << endl; } template class LinkedList { private: int myCount; public: Node *Head; Node *Tail; LinkedList(); Node *Get(int index); //Insert Operations void InsertHead(T val); void InsertTail(T val); void Insert(int index, T val); //Remove operations void RemoveHead(); void RemoveTail(); void Remove(int index); //Search operation int Search(T val); // Addition Operations int Count(); void PrintList(); }; template Node *LinkedList::Get(int index) { if (index < 0 || index > myCount) { return NULL; } Node *node = Head(); for (int i = 0; i < index; ++i) { node = node->Next; } return node; } template void LinkedList::InsertHead(T val) { Node *node = new Node(val); node->Next = Head; Head = node; if (myCount == 0) { Tail = Head; } myCount++; } template void LinkedList::InsertTail(T val) { if (myCount == 0) { InsertHead(val); return; } Node *node = new Node(val); Tail->Next = node; Tail = node; myCount++; } template void LinkedList::Insert(int index, T val) { if (index < 0 || index > myCount) { return; } if (index == 0) { InsertHead(val); return; } else if (index == myCount) { InsertTail(val); return; } Node *prevNode = Head; for (int i = 0; i < index - 1; ++i) { prevNode = prevNode->Next; } Node *nextNode = prevNode->Next; Node *node = new Node(val); node -> Next = nextNode; prevNode -> Next = node; myCount++; } template int LinkedList::Search(T val) { if (myCount == 0) { return -1; } int index = 0; Node * node = Head; while (node->Value != val) { index++; node = node-> Next; if (node == NULL) { return -1; } } return index; } int main() { Node *node1 = new Node(3.14); Node *node2 = new Node(6.92); Node *node3 = new Node(9.25); node1->Next = node2; node2->Next = node3; PrintNode(node1); return 0; }