# 2次元点群PointGroup pg
andrewScan(pg):
    Stack st
  orderedIndex ← pg.points をx を基準に、同じ場合はyを基準にソートしたインデックスの列

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

    for i ← 2 to pg.N-1:
        head = orderedIndex[i]
      
        while st.size() ≥ 2:
            top2 ← stの頂点の下の値
            top1 ← stの頂点の値
            if pg.points[top2] とpg.points[top1]がなす直線に対して
               pg.points[head]が左側にある(反時計回り):
                st.pop()
            else:
                break
        st.push(head)