乾貨1 頭結點鍊錶

2021-08-04 22:07:05 字數 2120 閱讀 6600

#include "linklist.h"

#include #include node * create_list()

// 頭插

int insert_head(node *h, linkdata data)

node->data = data;

node->next = h->next;

h->next = node;

return true;

}

// 尾插

int insert_last(node *h, linkdata data)

node->data = data;

node->next = null;

node* tmp = h;

while (tmp->next)

tmp->next = node;

return true;

}

// 從pos處插入

int insert_pos(node *h, int pos, linkdata data)

if (tmp == null) // 越界

node *node = (node*)malloc(sizeof(node)/sizeof(char));

if (node == null)

node->data = data;

node->next = tmp->next;

tmp->next = node;

return true;

}

// 根據下標刪除結點

int delete_pos(node* h, int pos)

if (tmp->next == null) // 越界

node *p = tmp->next;

tmp->next = p->next;

free(p);

return true;

}

// 逆序

int reverse_list(node *h)

h->next->next = null;

h->next = pre;

return true;

}

// 根據資料刪除結點

int delete_data(node* h, linkdata data)

if (tmp->next == null)

return false;

node *p = tmp->next;

tmp->next = p->next;

free(p);

return true;

}

// 搜尋結點

int find_element(node* h, linkdata data, int *x)

k++;

tmp = tmp->next; }

return false;

}

// 獲取結點資料

int get_element(node* h, int pos, int *x)

if (tmp == null)

return false;

else

*x = tmp->data;

return true;

}

// 獲取鍊錶長度

int get_len(node * h)

return count;

}

// 清空鍊錶

int clean_list(node * h)

return 0;

}

// 列印鍊錶

void display(node *h)

printf ("\n");

}

// 銷毀鍊錶

int destroy(node *h)

頭結點鍊錶練習

這是乙份關於頭結點鍊錶的問題 完成一些基本的煉表處理函式,包括插入,查詢,刪除,輸出等一些功能的實現 include include include linklist.h node creat list 尾插法 int insert last node head,linkdata data 頭插法 ...

無頭結點鍊錶

include include linklist.h struct node create linklist creat linklist 根據使用者輸入,建立乙個單鏈表 struct node pnew struct node malloc sizeof struct node pnew data...

鍊錶的虛擬頭結點

public class linkedlist public node e e public node override public string tostring 虛擬頭結點 private node dummyhead private int size public linkedlist 獲取...