線性表 陣列描述

2021-07-29 18:15:48 字數 1369 閱讀 9804

#ifndef arraylist_h_

#define arraylist_h_

#include#includetemplateclass arraylist

;templatearraylist::arraylist(int initcapacity)

arraylength = initcapacity;

element = new t[initcapacity];

listsize=0;

}/*線性表拷貝建構函式*/

templatearraylist::arraylist(const arraylist& thelist)

else

}/*線性表中加入乙個元素*/

templatevoid arraylist::add(t theelement)

else }

/*判斷線性表是否為空*/

templatebool arraylist::empty() const

else }

/*根據索引獲取元素值*/

templatet& arraylist::get(int theindex) const

else }

/*獲取線性表中第元素的下標*/

templateint arraylist::indexof(const t& theelement)

templatevoid arraylist::insert(int theindex,const t& theelemen)

if(listsize == arraylength)

copy(element+theindex,element+listsize,element+theindex+1);

element[theindex]=theelemen;

listsize++;

}/*線性表輸出操作*/

templatevoid arraylist::output() const

if(arraylength != thelist.arraylength)

bool equal = true;

for(int i=0;ivoid arraylist::changelength1d(t* &a,int oldlength,int newlength)

t* temp=new t[newlength];

int number =min(oldlength,newlength);

copy(a,a+number,temp);

delete a;

a=temp;

}/*析構函式*/

templatearraylist::~arraylist()

#endif

線性表描述字典

template struct pair template struct pairnode pairnode pairthepair,pair p template class dictionary virtual bool empty const 0 virtual int size const ...

筆記四 線性表 陣列描述

pragma warning disable 4996 include include include using namespace std typedef struct mytype template class linearlist 析構函式 virtual bool empty const ...

線性表的鏈式描述

1.概述 鏈式描述中,線性表的元素存在記憶體中的位置是隨機的。基於陣列的描述中,元素的位址是由數學公式決定的,而在鏈式描述中,元素的位址是隨機分布的.2.單向鍊錶 2.1 描述 資料物件的例項的每個元素都用乙個單元或節點來描述。每個節點都明確包含另乙個相關節點的位置資訊,稱為鏈或指標。一般來說,為找...