Source (Plain Text)
// Eingabe: Menge von Punkten in der Ebene (P)
// Ausgabe: Konvexe Huelle (H)
void scan (vector<Point2>& P, vector<Point2>& H) 
{

  if (P.size() <= 2) { H=P; return; }

  sort (P.begin(), P.end());
  H.push_back (P[0]); //linkester Punkt ist auf der Huelle

  int h = 0;
  
  // Untere Huelle (links nach rechts Scan)
  for (int i=1; i<P.size(); i++) {

    while (h>0 && cw (H[h-1], H[h], P[i])) { H.pop_back(); --h; }

    H.push_back (P[i]); ++h;
  }
  
  // Obere Huelle (rechts nach links Scan)
  for (int i=P.size()-2; i>=0; --i) {

    while (cw (H[h-1], H[h], P[i])) { H.pop_back(); --h; }

    H.push_back (P[i]); ++h;
  }
}