ImageVerifierCode 换一换
格式:DOCX , 页数:4 ,大小:15.86KB ,
资源ID:3256375      下载积分:1 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bingdoc.com/d-3256375.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(单链表的一个C实现Word下载.docx)为本站会员(b****2)主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(发送邮件至service@bingdoc.com或直接QQ联系客服),我们立即给予删除!

单链表的一个C实现Word下载.docx

1、initdata) : data(initdata), next(NULL) Node(const T &initdata, Node& *p) : data(initdata), next(p) ; class SList public: SList(); SList(const T &initdata); SList(const SList& other); SList& operator=(const SList& SList(); public: void Invert(); int IsEmpty() const; int GetCount() const; int InsertBe

2、fore(const int pos, const T data); int InsertAfter(const int pos, const T data); int AddHead(const T data); int AddTail(const T data); void RemoveAt(const int pos); void RemoveHead(); void RemoveTail(); void RemoveAll(); T& GetTail(); T GetTail() const; GetHead(); T GetHead() const; GetAt(const int

3、pos); T GetAt(const int pos) const; void SetAt(const int pos, T data); int Find(const T data) const; int FindCircle() const; int FindCross(SList& testlist); protected: int m_nCount; *m_pNodeHead; ; inline SList&:SList() : m_nCount(0), m_pNodeHead(NULL) template&SList(const T & m_nCount(0), m_pNodeHe

4、ad(NULL) AddHead(initdata); template&SList(const SList& other) : m_nCount(0), m_pNodeHead(NULL) if(other.m_nCount&0) for(int i=1;i&=other.m_nCount;i+) AddTail(other.GetAt(i); template&operator=(const SList& other) if(this=&other) return *this; if(m_nCount&0) RemoveAll(); if(other.m_nCount& return *t

5、his;SList() RemoveAll(); /reverse the list template& inline void SList&Invert() if(m_nCount&=1) return; *curNod,*preNod,*nextNod; curNod=m_pNodeHead; preNod=NULL; for(int i=1;=m_nCount;i+) nextNod=curNod-&next; curNod-&next=preNod; preNod=curNod; curNod=nextNod; m_pNodeHead=preNod; return; inline in

6、t SList&IsEmpty() const return 0 = m_nCount;AddHead(const T data) /*Node& *pNewNode; try pNewNode = new Node&; catch (std:bad_alloc&) return 0; pNewNode-&data = data; pNewNode-&next = m_pNodeHead; m_pNodeHead = pNewNode; +m_nCount; return 1;*/ return InsertBefore(1,data);AddTail(const T data) return

7、 InsertAfter(GetCount(), data); / if success, return the position of the new node. / if fail, return 0. template&InsertBefore(const int pos, const T data) int i; int nRetPos; *pTmpNode1; *pTmpNode2;) nRetPos = 0; return nRetPos; / if the list is empty, replace the head node with the new node. if (NU

8、LL = m_pNodeHead) pNewNode-&next = NULL; nRetPos = 1; / is pos range valid? ASSERT(1 &= pos & pos &= m_nCount); / insert before head node? if (1 = pos) pNewNode-& / if the list is not empty and is not inserted before head node, / seek to the pos of the list and insert the new node before it. pTmpNod

9、e1 = m_pNodeHead; for (i = 1; i & pos; +i) pTmpNode2 = pTmpNode1; pTmpNode1 = pTmpNode1-&next = pTmpNode1; pTmpNode2-&next = pNewNode; nRetPos = pos;InsertAfter(const int pos, const T data) int i; *pTmpNode; / if the list is not empty, / seek to the pos of the list and insert the new node after it.

10、pTmpNode = m_pNodeHead; +i) pTmpNode = pTmpNode-&next = pTmpNode-& pTmpNode-& nRetPos = pos + 1;GetCount() const return m_nCount;RemoveAt(const int pos) ASSERT(1 & int i; pTmpNode1 = m_pNodeHead; / head node? if (1 = pos) m_pNodeHead = m_pNodeHead-& delete pTmpNode1; -m_nCount; for (i = 1; +i) / we

11、will get the previous node of the target node after / the for loop finished, and it would be stored into pTmpNode2 pTmpNode2 = pTmpNode1; pTmpNode2-&next = pTmpNode1-&RemoveHead() ASSERT(0 ! RemoveAt(1);RemoveTail() ASSERT(0 ! RemoveAt(m_nCount);RemoveAll() int i; int nCount; nCount = m_nCount; if(n

12、Count=0) return; for (i = 0; nCount; +i) pTmpNode = m_pNodeHead-& delete m_pNodeHead; m_pNodeHead = pTmpNode; m_pNodeHead=NULL; m_nCount = 0; inline T&GetTail() ASSERT(0 ! *pTmpNode = m_pNodeHead; return pTmpNode-&data; inline T SList&GetTail() const ASSERT(0 !GetHead() ASSERT(0 ! return m_pNodeHead

13、-&GetHead() const ASSERT(0 !GetAt(const int pos) ASSERT(1 &GetAt(const int pos) const ASSERT(1 &SetAt(const int pos, T data) ASSERT(1 & pTmpNode-&Find(const T data) const int i; for (i = 0; +i) if (data = pTmpNode-&data) return i + 1; pTmpNode = pTmpNode-& return 0; /*判断链表是否有环,如果有环则返回环的首结点位置,否则返回0*/

14、 template&FindCircle() const if(0=m_nCount) return 0; Node&* p1=m_pNodeHead;* p2=m_pNodeHead; /*判断链表是否有环,当p1=p2时说明链表有环,程序跳出循环。如果p2一直走到链表尽头则说明没有环。*/ do if(p1!=NULL&p2!p2-&next!=NULL) p1=p1-& p2=p2-&next-& else return 0; while(p1!=p2); /*求出环的起点节点,并将其返回*/ p2=m_pNodeHead; while(p1!=p2) p1=p1-& int i; p2

15、=m_pNodeHead; for(i=1;i+) if(p1=p2) break; return i; /*判断两个链表是否交叉,如果交叉返回首个交叉节点位置(在本链表中的位置,而不是testlist中的位置),否则返回0。 假定:这两个链表本身均无环*/ template&FindCross(SList& testlist) if(0=m_nCount|0=testlist.m_nCount) return 0; if(FindCircle()|testlist.FindCircle() return 0; /*将第二个链表接在第一个链表后面*/ Node&* pTail=m_pNodeHead;m_nCount;i+) pTail=pTail-& pTail=testlist.m_pNodeHead; m_nCount+=testlist.m_nCount; int i=FindCircle(); pTail=NULL; m_nCount-=testlist.m_nCount; return i; #endif

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2