cs101-notes
  • CS 101 Notes
  • Big O Notation
  • Big O Cheat Sheet
  • Sorting
    • Summary
    • Bubble Sort
    • Selection Sort
    • Insertion Sort
    • Merge Sort
    • Quick Sort
  • Abstract Data Types
    • Linked List
    • Stack
    • Queue
    • Hash Maps
    • Minimum Ordered Heap
Powered by GitBook
On this page

Was this helpful?

  1. Abstract Data Types

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;
  }
PreviousQuick SortNextStack

Last updated 5 years ago

Was this helpful?