关键词:链表,增删改查操作。
head pointer 插入删除会影响头指针
|
??? [ ] -> [ ] -> [ ]
head node 常用方法,即头指针为空
[x] -> [ ] -> [ ]
C实现
初始化
struct Node {
int data;
struct Node* next;
};
//typedef struct Node* LList; 取别名
void init(struct Node** phead ) {
*phead = NULL;
}
创建节点
struct Node* createNode(int x) {
struct Node* t;
t = (struct Node*)malloc(sizeof(struct Node));
t->next = NULL;
t->data = x;
return t;
}
查找第K个节点
struct Node* findKth(struct Node* head, int k) {
int count =1;
struct Node* p;
p = head;
while(p && count <k) {
p = p->next;
count++;
}
return p;
}
在K处插入节点