Linked List - C P P

  • Dynamic Liner data structure made by collection of Nodes
  • Node
    • Data & Next Node Address
    • Last Node points to NULL
    • Head pointer points to 1st Node
    • Tail pointer points to last Node => Optional
  • Insert/Delete/Traverse Node
    • At Head/Start
    • At Tail/End
    • In Middle
  • Types
    • Singly
      • #include <forward_list> => Header to include
      • forward_list<dataType> variable => Declare
      • variable.assign({ value1, value2, value3 }); => Assigning values
        • variable.assign(value1, value2); => Assign value2 elements, value1 number of times
    • Doubly
      • #include <list> => Header to include
      • list<dataType> variable => Declare a list
      • list<dataType> var1(variable) => Initialize a list by copying another list
      • list<dataType> variable(n1, n2) => Initialize a list with "n1" elements by "n2" value
      • variable.push_front(value) => Insert element in the front
      • variable.push_back(value) => Insert element in the back
      • variable.erase(l.begin()) => Deletes the element that the iterator points to
      • variable.pop_front() => Remove element from the front
      • variable.pop_back() => Remove element from the back
      • variable.size() => Returns size of list
    • Circular
    • Circular Doubly
Share: