带智能指针的链表

智能指针(各有缺陷):

auto_ptr:       独占所有权---管理权转移
scoped_ptr:     独占所有权---防拷贝(简单粗暴)
shared_ptr:     共享所有权---增加引用计数
weak_ptr:       弱引用指针---shared_ptr的附属,
                 解决share_ptr循环引用带来的缺陷

C++封装的带智能指针链表:

#include <memory>

using std::tr1::shared_ptr;

struct linkNode
{
	int data;
	shared_ptr<linkNode> next;	
};
class linkedList
{
private:
	int length;
	shared_ptr<linkNode> head;

public:
	linkedList();
	linkedList(const linkedList& theList);

	bool empty()const
	{
		return length == 0;
	}
	int size()const
	{
		return length;
	}

	int get(int theIndex)const;
	int indexOf(const int& theList);
	void insert(int theIndex, const int& theElement);
	void erase(int theIndex);
	//void oouput(ostream& out) const;

};

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值