資料結構之鍊錶

2021-08-19 20:58:11 字數 1027 閱讀 2626

一、定義

鍊錶是一種常用的資料結構,而且我後面棧和fifo也是用鍊錶結構實現的,所以你必須得對

鍊錶非常熟悉。它的查詢時間複雜度為o(n),而它的插入複雜度為o(1),所以當你的資料不

斷的變化時這時候用鍊錶是非常好的。

二、使用

typedef  int seqtype;

typedef struct node//定義資料節點

node;

typedef struct header//定義順序表頭

header;

header *creat_list()

bool insert_list(header *header,node *node,int pos)//找到指定位置插入資料

if(header->p == null)

for(int i=0;inext ;

} node->next = current->next ;

current->next = node;

header->length ++;

return true;

}bool delete_list(header *header,int pos)//刪除指定位置的元素

if(header->length == 0)

for (int i = 0;inext ;

} tem = current->next;

current->next = current->next->next ;

free(tem);

header->length --;

return true;

}bool destory_list(header *header)//摧毀鍊錶 保留頭節點

while(current) }

int main()//在此頭節點不算資料節點

歡迎各位指出不足之處

資料結構 表之煉表

頭插法建立 尾插法建立 顯示 銷毀 include include using namespace std typedef int elemtype typedef struct lnode linklist void createlinklistf linklist l,elemtype a,in...

資料結構之鍊錶

頭結點 第乙個有效結點之前的那個結點 頭結點並不存有效資料 加頭結點的目的主要是為了方便對鍊錶的操作 頭指標 指向頭結點的指標變數 尾指標 指向尾節點的指標變數 如果希望通過乙個函式對鍊錶進行處理,只需要乙個引數 頭指標 首先要定義乙個單鏈表儲存結構 然後建立乙個空表,即初始化,我寫的這個提前設定好...

資料結構之鍊錶

鍊錶是一種基本的資料結構型別,它由乙個個結點組成。每乙個結點包括乙個資料的儲存和乙個指向下乙個結點的引用。在這個定義中,結點是乙個可能含有任意型別資料的抽象實體,它所包含的指向結點的應用顯示了它在構造鍊錶之中的作用。和遞迴程式一樣,遞迴資料結構的概念一開始也令人費解,但其實它的簡潔性賦予了它巨大的價...