网站大量收购独家精品文档,联系QQ:2885784924

[工学]数据结构 C++源代码.doc

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

1、顺序表 Seqlist.h const int DefaultSize=100; template typename Type class SeqList{ public: SeqList(int sz=DefaultSize) :m_nmaxsize(sz),m_ncurrentsize(-1){ if(sz0){ m_elements=new Type[m_nmaxsize]; } } ~SeqList(){ delete[] m_elements; } int Length() const{ //get the length return m_ncurrentsize+1; } int Find(Type x) const; //find the position of x int IsElement(Type x) const; //is it in the list int Insert(Type x,int i); //insert data int Remove(Type x); //delete data int IsEmpty(){ return m_ncurrentsize==-1; } int IsFull(){ return m_ncurrentsize==m_nmaxsize-1; } Type Get(int i){ //get the ith data return i0||im_ncurrentsize?(coutcant find the elementendl,0):m_elements[i]; } void Print(); private: Type *m_elements; const int m_nmaxsize; int m_ncurrentsize; }; template typename Type int SeqListType::Find(Type x) const{ for(int i=0;im_ncurrentsize;i++) if(m_elements[i]==x) return i; coutcant find the element you want to findendl; return -1; } template typename Type int SeqListType::IsElement(Type x) const{ if(Find(x)==-1) return 0; return 1; } template typename Type int SeqListType::Insert(Type x, int i){ if(i0||im_ncurrentsize+1||m_ncurrentsize==m_nmaxsize-1){ coutthe operate is illegalendl; return 0; } m_ncurrentsize++; for(int j=m_ncurrentsize;ji;j--){ m_elements[j]=m_elements[j-1]; } m_elements[i]=x; return 1; } template typename Type int SeqListType::Remove(Type x){ int size=m_ncurrentsize; for(int i=0;im_ncurrentsize;){ if(m_elements[i]==x){ for(int j=i;jm_ncurrentsize;j++){ m_elements[j]=m_elements[j+1]; } m_ncurrentsize--; continue; } i++; } if(size==m_ncurrentsize){ coutcant find the element you want to removeendl; return 0; } return 1; } template typename Type void SeqListType::Print(){ for(int i=0;i=m_ncurrentsize;i++) couti+1:\tm_elements[i]endl; coutendlendl; } Test.cpp #include iostream #include SeqList.h using namespace std; int main() {

文档评论(0)

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

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

1亿VIP精品文档

相关文档