关于最近点对问题:根据点的X坐标大小排序后画出的点数减少,为什么?

我要画10个圆点,如果没有对随机生成的点进行排序的话,画出来的点数是正常的,如果排序后画出来的点数会减少,有时画6个有时画7个有时画8个,我调试了但找不出问题,请各路大神帮忙看看,谢谢!
//随机生成点集并按横坐标排序
void CClosestPointDlg::CreateLogicalPoints(int num)
{
m_picDraw.GetClientRect(&rectPicture);
while (m_lpoints.GetCount() < num)
{
CPoint p(rand() % rectPicture.Width() ,rand() % rectPicture.Height());

    if (!m_lpoints.Find(p))
    {
        m_lpoints.AddTail(p);
    }
}

CPoint p1(0,0),p2(0,0),temp_p(0,0);
//POSITION cur_pos,late_pos;
 for (int i = 0; i < m_lpoints.GetCount() - 1; i++)
        {
            POSITION cur_pos = m_lpoints.FindIndex(i);
            p1 = m_lpoints.GetAt(cur_pos);

                 for (int j = i + 1; j < m_lpoints.GetCount(); j++)
                {
                    POSITION late_pos = m_lpoints.FindIndex(j);
                    p2 = m_lpoints.GetAt(late_pos);
                    if (p1.x > p2.x)
                    {
                        temp_p = p1;
                        p1 = p2;
                        p2 = temp_p;
                        m_lpoints.SetAt(cur_pos,p2);
                        m_lpoints.SetAt(late_pos,p1);
                     }
                 }


        }

}

//画点函数
void CClosestPointDlg::DrawPoints(CList *points, COLORREF color)
{
Radius = 5;
CClientDC clientDC(this);
newBrush.CreateSolidBrush(color);
// 选择新画刷,并保存旧画刷的指针到pOldBrush

pOldBrush = clientDC.SelectObject(&newBrush);

         for (int i=0;i < points->GetCount(); i++)
                {
                    POSITION pos = points->FindIndex(i);
                    CPoint p = points->GetAt(pos);
                    clientDC.Ellipse(p.x - Radius,p.y - Radius,p.x + Radius,p.y + Radius);
                 }

        clientDC.SelectObject(pOldBrush);   
        // 删除新画刷   
        newBrush.DeleteObject();   
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问