我是这样想的:
1)找到我要改变位置的元素目前所在的位置currentPos
2)将该元素删除,CMyList.RemoveAt(currentPos);
3) 重新设置元素的位置
CMyList.SetAt(element,destiPos);
或者CMyList.InsertAfter(prePos,element);
CMyList.InsertBefore(backPos,element);
编译通过,执行后不是我想要的效果。
郁闷中。。
1)找到我要改变位置的元素目前所在的位置currentPos
2)将该元素删除,CMyList.RemoveAt(currentPos);
3) 重新设置元素的位置
CMyList.SetAt(element,destiPos);
或者CMyList.InsertAfter(prePos,element);
CMyList.InsertBefore(backPos,element);
编译通过,执行后不是我想要的效果。
郁闷中。。
CMyBmpInfo bmpInfo;
int nCounter,nIndex;
nCounter = bmpInfoList.GetCount();
nIndex = 0; //找到目的地保存在destiPos中
for(pos = bmpInfoList.GetHeadPosition(); pos!=NULL;)
{
temp = pos;
bmpInfo = bmpInfoList.GetNext(pos);
if(!bmpInfo.m_bPassRight)
{
destiPos = temp;
break;
}
} //找到原地址并删掉
CMyBmpInfo * pInfo;
for(pos = bmpInfoList.GetHeadPosition();pos!=NULL;)
{
temp = pos;
pInfo = &(bmpInfoList.GetNext(pos));
nIndex ++;
if(pBmpInfo == pInfo )
{
bmpInfoList.RemoveAt(temp);
break;
}
} //将原内容保存在新地址中
bmpInfo = *pBmpInfo;
if(nIndex == 1)
bmpInfoList.AddHead(bmpInfo);
if(nIndex == nCounter)
bmpInfoList.AddTail(bmpInfo);
if(nIndex > 1 && nIndex < nCounter)
bmpInfoList.InsertAfter(destiPos,bmpInfo);