頭結點鍊錶練習

2021-08-04 19:59:26 字數 1490 閱讀 1203



//這是乙份關於頭結點鍊錶的問題

//完成一些基本的煉表處理函式,包括插入,查詢,刪除,輸出等一些功能的實現

#include

#include

#include"linklist.h"

node *creat_list()

//尾插法

int insert_last(node *head,linkdata data)

//頭插法

int insert_head(node *head,linkdata data)

//在pos處插入資料

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

if(tmp==null)

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

if(node==null)

return false;

node->data=data;

node->next=tmp->next;

tmp->next=node;

return true;

}//刪除結點

int delete_pos(node *head,int pos)

node *p=tmp->next;

tmp->next=p->next;

free(p);

}// 逆序

int reverse_list(node *head)

head->next->next==null;

head->next=pre; 

return true;

}int delete_data(node *head,linkdata data)

if(tmp->next==null)

return false;

node *p=tmp->next;

tmp->next=p->next;

free(p);

return true;

}int find_element(node *head,linkdata data,int *x)

k++; 

tmp=tmp->next;

}return true;

}int get_element(node *head,int pos,int *x)

if(tmp==null)

else

*x=tmp->data;

return true;

}int get_len(node *head)

return count;

}int clean_list(node *head);

return false;

}void display(node *head)

printf("%4d",tmp->data);

tmp=tmp->next;}}

int destroy(node *head)

無頭結點鍊錶

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

乾貨1 頭結點鍊錶

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 尾插...

鍊錶的虛擬頭結點

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