线性表物理实现(顺序表和链表).ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
线性表物理实现(顺序表和链表)

第4章 线性表、栈和队列 线性表的实现 线性表的实现有两种标准方法 顺序表(array-based list) 链表(linked list) 顺序表的实现方法 链表的实现方法 比较两种方式的时间、空间效率 线性表的顺序表实现的原则 线性表ADT? 顺序表的特点? 用顺序表来实现线性表的物理数据结构,要实现一些什么? Array-Based List Class (1) template class Elem // Array-based list class AList : public ListElem { private: int maxSize; // Maximum size of list int listSize; // Actual elem count int fence; // Position of fence Elem* listArray; // Array holding list public: AList(int size=DefaultListSize) { maxSize = size; listSize = fence = 0; listArray = new Elem[maxSize]; } Array-Based List Class (2) ~AList() { delete [] listArray; } void clear() { delete [] listArray; listSize = fence = 0; listArray = new Elem[maxSize]; } void setStart() { fence = 0; } void setEnd() { fence = listSize; } void prev() { if (fence != 0) fence--; } void next() { if (fence = listSize) fence++; } int leftLength() const { return fence; } int rightLength() const { return listSize - fence; } Array-Based List Class (3) bool setPos(int pos) { if ((pos = 0) (pos = listSize)) fence = pos; return (pos = 0) (pos = listSize); } bool getValue(Elem it) const { if (rightLength() == 0) return false; else { it = listArray[fence]; return true; } } Append // Append Elem to end of the list template class Elem bool AListElem::append(const Elem item) { if (listSize == maxSize) return false; listArray[listSize++] = item; return true; } Array-Based List Insert Insert // Insert at front of right partition template class Elem bool AListElem::insert(const Elem item) { if (listSize == maxSize) return false; for(int i=listSize; ifence; i--) // Shift Elems up to make room listArray[i] = listArray[i-1]; listArray[fence] = item; listSize++; // Increment list size return true; } Remove // Remove and return first Elem in right // partition template class Elem bool AListElem::remove(Elem it) { if (rightLength() == 0) return false; it = listArray[fence]; // Co

文档评论(0)

wyjy + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档