previous | start | next

## Linked Lists

- The end position is useful for stopping a traversal of the list.

  >     pos = staff.begin();
  >     while (pos != staff.end())
  >     {
  >        cout << *pos << "\n";
  >        pos++;
  >     }

- The traversal can be described more concisely with a `for` loop:

  >     for (pos = staff.begin(); pos != staff.end(); pos++)
  >        cout << *pos << "\n";

- Compare this to a traversal of a vector.

  >     for (i = 0; i < s.size(); i++)
  >        cout << s[i] << "\n";

- To remove an element from a list, you move an iterator to the position you want to remove, then call the erase function.

  >     pos = staff.begin();
  >     pos++;
  >     staff.erase(pos);

previous | start | next