# 二维点群 PointGroup pg
andrewScan(pg):
Stack st
orderedIndex ← 以 x 为基准,若 x 相同则以 y 为基准,对 pg.points 进行排序的索引列表
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[top] 连起来的直线
pg.points[head]处于左侧(逆时针):
st.pop()
else:
break
st.push(head)