Linked List

A list is an abstract data type for holding a set of like data.

template <typename eType>
struct List {
  struct Node {
    eType data;
    Node* next;
    Node(eType d, Node* p = 0) {
      data = d;
      next = p;
    }
  };
  Node* head;
};
 int length(List* myList = nullptr) {
   if (!myList) myList = *this;
   if (!myList->head) return 0;
   return 1 + length(myList->next);
 }
  Node front() { return &head; }
  
  Node back() {
    auto* ptr = head;
    while (ptr->next) ptr = ptr->next;
    return &ptr;
  }

Last updated

Was this helpful?