# 二维点群 PointGroup pg
grahamScan(pg):
    Stack st
    leftmost ← pg.points最左下的点
  orderedIndex ← 将 pg.points 以 leftmost 为基准按照极角排序的索引列表

    st.push(orderedIndex[0])
    st.push(orderedIndex[1])
    st.push(orderedIndex[2])

    for i ← 3 to pg.N-1:
        head = orderedIndex[i]
      
        while st.size() ≥ 2:
            top2 ← st的顶点下面的点的值
            top ← st的顶点的值
            if 相对于将 pg.points[top2] 和 pg.points[top] 连起来的直线
               pg.points[head]处于右侧(顺时针):
                st.pop()
            else:
                break
        st.push(head)