int Index = 0;
CList <CPoint , CPoint &> listPoint;
//判断是否为空
BOOL bRet = listPoint.IsEmpty();
//循环插入<x y>数据
for (Index = 0; Index < 100; Index++)
{
CPoint pt(Index , Index);
listPoint.AddTail(pt);
}
//获取列表元素总数
int nGetCount = listPoint.GetCount();
int nGetSize = listPoint.GetSize();
//获取列表头元素的位置
POSITION pi = listPoint.GetHeadPosition();
//获取列表尾元素的位置
pi = listPoint.GetTailPosition();
//通过RemoveAt函数 删除指定索引5的元素 删除之后 类会自动修改表头和表尾地址
listPoint.RemoveAt(listPoint.FindIndex(5));
//通过GetAt函数获取索引为5的值 因为不是数组 在内存中的位置并不是连续的 所以不可以通过下标读取或设置
CPoint getpt = (0,0);
getpt = listPoint.GetAt(listPoint.FindIndex(5)); //通过FindIndex函数返回 POSITION 类型
//通过SetAt函数设置索引为10的值
getpt = (321,321);
listPoint.SetAt(listPoint.FindIndex(10),getpt);
//遍历链表
pi = listPoint.GetHeadPosition();
for (Index = 0; Index < listPoint.GetCount(); Index++)
{
getpt = listPoint.GetNext(pi);
}
//删除链表中所有元素 清空所有的pNext pPrev data数据
listPoint.RemoveAll();
//判断列表元素总数
nGetCount = listPoint.GetCount();