線性表(一) 鍊錶之靜態鍊錶

2021-09-28 11:05:02 字數 1150 閱讀 7135

五、靜態鍊錶的實現

//定義靜態節點

template class staticlistnode

;template class staticlist

//鍊錶是否為空

bool empty()

//獲取頭結點

listnode*get_head()

//插入節點

void insert(const int &index,const t &value);

//刪除節點

t erase(const int &index);

//修改節點

void set(const int &index,const t &value);

//查詢節點

t &get(const int &index);

//獲取鍊錶值對應下標

int get_index(const t &value);

//列印鍊錶

void print();

void print_link();

private:

staticlistnode*head_; //鍊錶的頭節點

int data_head_; //資料節點的頭節點

size_t size_; //鍊錶的大小

size_t capacity_; //鍊錶的容量

};template staticlist::staticlist(const size_t &capacity)

:head_(nullptr),size_(0),capacity_(capacity)

template void staticlist::insert(const int &index, const t &value)

temp_head=head_[temp_head].next;

}return -1;

}template void staticlist::print()

{ int temp_head=data_head_;

while(head_[temp_head].next!=0){

cout<"<"{ for(int i=0;i"《資料結構6: 靜態鍊錶及c語言實現

靜態鍊錶

線性表 靜態鍊錶

靜態鍊錶的優缺點 優點 1 在插入和刪除操作時,只需要改變游標cur,不需要移動元素,從而改進了在順序儲存結構中的插入和刪除中需要移動大量元素的缺點 缺點 1 沒有解決連續儲存分配帶來的表長難以確定的問題 2 失去了順序儲存結構隨機訪問的特性 includeusing namespace std d...

線性表 靜態鍊錶

靜態鍊錶,是通過游標來記錄下乙個節點的位置,約定第乙個游標指向備用列表的頭,最後乙個游標指向靜態鍊錶的頭,比如 函式宣告 status static list init static list space status search bp positon static list space stat...

線性表之鍊錶

鏈式的線性表適用於經常進行刪除,插入操作的工作,如 訂票系統。鍊錶是用乙個乙個的節點連線起來的表,在物理上不是連續的,在邏輯上是連續的。通過節點間的指標指向來表示節點間的關係。所以在進行鍊錶操作之前,要先定義乙個節點結構。節點結構包含兩個東西 資料域,指標域。資料域就是用來存放資料的,指標域是用來表...