数据结构与算法分析

数据结构与算法分析

ID:19506931

大小:141.50 KB

页数:16页

时间:2018-10-02

数据结构与算法分析_第1页
数据结构与算法分析_第2页
数据结构与算法分析_第3页
数据结构与算法分析_第4页
数据结构与算法分析_第5页
资源描述:

《数据结构与算法分析》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、[首页,上一页,下一页;  目录]第二章单链表链表是最常用、最简单和最基本的数据结构之一。我们先来看看单链表的实现。2.1  代码实现单链表的实现如下:///////////////////////////////////////////////////////////////////////////////////FileName:slist.h//Version:0.10//Author:LuoCong//Date:2004-12-299:58:38//Comment://////////////////////////////////////////////

2、///////////////////////////////////#ifndef__SINGLE_LIST_H__#define__SINGLE_LIST_H__#include#include#ifdef_DEBUG#defineDEBUG_NEWnew(_NORMAL_BLOCK,THIS_FILE,__LINE__)#endif#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#endif#ifdef_DEBUG

3、#ifndefASSERT#defineASSERTassert#endif#else//not_DEBUG#ifndefASSERT#defineASSERT#endif#endif//_DEBUGtemplateclassCNode{public:Tdata;CNode*next;CNode():data(T()),next(NULL){}CNode(constT&initdata):data(initdata),next(NULL){}CNode(constT&initdata,CNode*p):data(initdata)

4、,next(p){}};templateclassCSList{protected:intm_nCount;CNode*m_pNodeHead;public:CSList();CSList(constT&initdata);~CSList();public:intIsEmpty()const;intGetCount()const;intInsertBefore(constintpos,constTdata);intInsertAfter(constintpos,constTdata);intAddHead(constTdata);int

5、AddTail(constTdata);voidRemoveAt(constintpos);voidRemoveHead();voidRemoveTail();voidRemoveAll();T&GetTail();TGetTail()const;T&GetHead();TGetHead()const;T&GetAt(constintpos);TGetAt(constintpos)const;voidSetAt(constintpos,Tdata);intFind(constTdata)const;};templateinlineCSList

6、::CSList():m_nCount(0),m_pNodeHead(NULL){}templateinlineCSList::CSList(constT&initdata):m_nCount(0),m_pNodeHead(NULL){AddHead(initdata);}templateinlineCSList::~CSList(){RemoveAll();}templateinlineintCSList::IsEmpty()const{return0==m_nCount;

7、}templateinlineintCSList::AddHead(constTdata){CNode*pNewNode;pNewNode=newCNode;if(NULL==pNewNode)return0;pNewNode->data=data;pNewNode->next=m_pNodeHead;m_pNodeHead=pNewNode;++m_nCount;return1;}templateinlineintCSList::AddTail(constTdata){returnInsertA

8、fter(

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。