# 二維點群 PointGroup pg
andrewScan(pg):
    Stack st
    orderedIndex ← 以 x 為基準對 pg.points 進行排序後的索引序列
                        若多點相同再以 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 頂端數來第 2 個值
            top1 ← st 頂端數來第 1 個值
            if p[top2] 對於 pg.points[top2] 與 pg.points[top] 形成的直線而言
                            pg.points[head] 位於左側(逆時針方向):
                st.pop()
            else:
                break
        st.push(head)