資料結構線性表之實現順序表 三

2021-10-13 22:01:42 字數 2043 閱讀 1124

**例項

資料結構線性表之概念(一)

資料結構線性表之抽象基類(二)

資料結構線性表之實現順序表(三)

//建構函式

//@param sz 順序表大小

template

<

class

t>

inline

seqlist

::seqlist

(int sz)}}

//複製構造引數

//@param l 待複製的線性表

template

<

class

t>

inline

seqlist

::seqlist

(seqlist

& l)

else

}}

template

<

class

t>

intseqlist

::search

(t& x)

const

template

<

class

t>

intseqlist

::locate

(int i)

const

//獲取順序表第i個元素

//@param i 元素位置(從1開始)

//@param x 獲取到的元素

//@return bool 獲取資料的結果

template

<

class

t>

inline

bool

seqlist

::getdata

(int i, t& x)

const

else

}//設定順序表第i個元素

//@param i 元素位置(從1開始)

//@param x 設定的元素

template

<

class

t>

inline

void

seqlist

::setdata

(int i, t& x)

else

}

template

<

class

t>

bool

seqlist

::insert

(int i, t& x)

template

<

class

t>

inline

bool

seqlist

::remove

(int i, t& x)

template

<

class

t>

inline

bool

seqlist

::isempty()

const

template

<

class

t>

inline

bool

seqlist

::isfull()

const

template

<

class

t>

inline

void

seqlist

::input()

cout <<

"請依次輸入元素"

<< endl;

for(

int i =

0; i < last; i++)}

template

<

class

t>

inline

void

seqlist

::output()

}

資料結構 線性表 順序表

豐富了前邊的功能,更加完善。include include define list init size 100 線性表儲存空間的初始分配量 define listincrement 10 線性表儲存空間的分配增量 using namespace std const int overflow 2 ty...

資料結構 線性表 順序表

線性表是具有相同特性的資料元素的乙個有限序列。線性表的順序儲存結構是,把線性表中的所有元素按照其邏輯順序依次儲存到從計算機儲存器中指定的儲存位置開始的一塊連續的儲存空間。include include include define maxsize 50 using namespace std 假設l...

資料結構 線性表(順序表)

順序表就是把線性表中的所有元素按照其邏輯順序,依次儲存到從指定的儲存位置開始的一塊連續的儲存空間中。這樣線性表中第乙個元素的儲存位置就是指定的儲存位置,第i 1個元素的儲存位置緊接在第i個元素的儲存位置的後面。順序表就像如下圖中的房子,每個房間左邊的數字就是該房間離0點的距離,同時也代表了房間號,房...