- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Type getData (return data ) ; void Firster ( ) { current = first; } int First ( ); int Next ( ); int Prior ( ); int operator ! ( ) { return current != NULL; } void Insert ( const Type value ); void Remove ( ); private: DblNodeType *first, *current; }; 搜索成功 搜索不成功 双向循环链表的搜索算法 template class Type int DblListType:: Find ( const Type target ) { //在双向循环链表中搜索含target的结点, //搜索成功返回1,否则返回0。 DblNodeType *p = first→rLink; while ( p != first p→data != target ) p = p→rLink; //循链搜索 if ( p != first ) { current = p; return 1; } return 0; } p→lLink = current; p→rLink =current→rLink; current→rLink = p; current = current→rLink; current→rLink→lLink = current; 双向循环链表的插入算法(在current后插入) p template class Type void DblListType:: Insert ( const Type value ) { if ( current == NULL ) //空表情形 current = first→rLink = new DblNode ( value, first, first ); else { //非空表情形 current→rLink =new DblNode ( value, current, current→rLink ); current = current→rLink; } current→rLink→lLink = current; } current→rLink→lLink = current→lLink; current→lLink→rLink = current→rLink; 双向循环链表的删除算法删除current指向的结点 template class Type void DblListType::Remove ( ) { if ( current != NULL ) { DblNode *temp = current; current = current→rLink; current→lLink = temp→lLink; temp→lLink→rLink = current; delete temp; if ( current == first ) if ( IsEmpty ( ) ) current = NULL; else current = current→rLink; } } 其他双向循环链表的公共操作 template class Type DblListType::DblLIst ( Type uniqueVal ) { //双向循环链表的构造函数, 创建表头结点 first = new DblNodeType ( uniqueVal ); first→rLink = first→lLink = first; current = NULL; } template class Type int DblListType::Length ( ) const { //求双向循环链表的长度(不计表头结点) DblNodeType * p = first→rLink; int count = 0; while ( p != first )
文档评论(0)