我用MFC里的CList类做的一个链表的冒泡排序,不知道哪里有问题,总是弹出错误。
voidCStudent::BubbleSort(){POSITIONpos=m_list.GetHeadPosition();POSITIONp=pos;inti,j,...
void CStudent::BubbleSort()
{
POSITION pos = m_list.GetHeadPosition();
POSITION p = pos;
int i, j,count=0;
DATA t;
count = m_list.GetCount();
for ( i = 0; i <count-1; i++)
{
pos = m_list.GetHeadPosition();
for ( j = 0; j < count-i-1; j++)
{
m_list.GetNext(p);
if (m_list.GetAt(pos).nNumb>m_list.GetAt(p).nNumb)
{
t = m_list.GetAt(pos);
m_list.SetAt(pos, m_list.GetAt(p));
m_list.SetAt(p, t);
}
m_list.GetNext(pos);
p = pos;
}
}
} 展开
{
POSITION pos = m_list.GetHeadPosition();
POSITION p = pos;
int i, j,count=0;
DATA t;
count = m_list.GetCount();
for ( i = 0; i <count-1; i++)
{
pos = m_list.GetHeadPosition();
for ( j = 0; j < count-i-1; j++)
{
m_list.GetNext(p);
if (m_list.GetAt(pos).nNumb>m_list.GetAt(p).nNumb)
{
t = m_list.GetAt(pos);
m_list.SetAt(pos, m_list.GetAt(p));
m_list.SetAt(p, t);
}
m_list.GetNext(pos);
p = pos;
}
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询