CList 简单用法

首先来看微软原文

template< class TYPE, class ARG_TYPE = const TYPE& > 
class CList : public CObject
TYPE
Type of object stored in the list.
ARG _ TYPE
Type used to reference objects stored in the list. Can be a reference.

首先大家明白一点,CList就是一个 链表

然后,需要知道 如何定义并且使用

这里是一个简单的例子

#include "stdafx.h"
#include <afxtempl.h>

int main(int argc, char* argv[])
{
	CList <int,int> nList;

	{
		for (int i = 0 ; i < 10; i++ )
		{
			nList.AddTail(i);
		}
		
		POSITION pos = nList.GetHeadPosition();
		while(pos)
		{
			printf("%d - ",nList.GetNext(pos));
		}
		printf("\r\n");
	}

	return 0;
}
大家可以自己运行一下,我每次都试图用最简单的例子来说明问题

接下来,我在给出一个例子

#include "stdafx.h"
#include <afxtempl.h>


int main(int argc, char* argv[])
{
	CList <int*,int*> nList;
	int nArry[10]={0};
	{
		for (int i = 0 ; i < 10; i++ )
		{
			nArry[i] = i;
			nList.AddTail(nArry+i);
		}
		
		POSITION pos = nList.GetHeadPosition();
		while(pos)
		{
			printf("%d - ",*nList.GetNext(pos));
		}
		printf("\r\n");
	}

	return 0;
}

通过两个简单的例子,大家可以初步了解这个东西,,剩下的大家可以参照别人写的例子!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值