typedef
int elemtype;
typedef
struct node
;struct node *next;
}headlist;
有頭結點的單鏈表
#include
"headlist.h"
#include
#include
#include
static headlist*
(elemtype val, headlist *nt)
//申請新的結點
void
initheadlist
(headlist * head)
//初始化
intgetlength
(headlist *head)
//求出長度
return length;
}void
showlist
(headlist *head)
//輸出鍊錶值
printf
("\n");
}bool insertofpos
(headlist *head, elemtype val,
int pos)
//按位置插入
if(p ==
null
)return false;
headlist *newnode =
(val, p->next);if
(newnode ==
null
)return false;
p->next = newnode;
return true;
}bool insertofhead
(headlist *head, elemtype val)
//頭插
bool insertoftail
(headlist *head, elemtype val)
//尾插
bool deleteofpos
(headlist *head,
int pos)
//按位置刪除
if(p->next ==
null
)return false;
// pos越界的情況
headlist *q = p->next;
// q就是要刪除的節點
p->next = q->next;
free
(q);
return true;
}bool deleteofhead
(headlist *head)
//頭刪除
bool deleteoftail
(headlist *head)
//尾刪
p->next =
null
;free
(q);
return true;
}// 將所有重複的值都刪除
bool deleteofvalue
(headlist *head, elemtype val)
else
}return true;
}void
destroyheadlist
(headlist *head)
//銷毀
}void
clearheadlist
(headlist *head)
//清除
有頭結點的單鏈表(java實現)
class node node int data class list public void insert int data node.next tmp.next tmp.next node public void delete int data tmp tmp.next public void ...
單鏈表操作 頭結點方式
單鏈表 訪問時,只能通過表頭遍歷進行訪問,遍歷結束的條件是最後乙個節點的為null。單鏈表中可以分為資料域和指標域。資料域為使用者儲存資料的變數。指標域則指向下乙個節點。一般單鏈表操作可以分為頭節結方式和頭指標方式 struct node root null 方式。由於單鏈表訪問節點只有一條路徑,因...
有頭單鏈表排序
1 有頭頭插單鏈表排序 思路 遍歷比較原鍊錶,將最小的數取出插入新的鍊錶 按照尾插的順序插入 include include typedef struct person per per head list per one,int num 有頭頭插 void show per head 遍歷列印 wh...