• 欢迎光临~

# 链表的实现

## 顺序表的链式存储

``````#include <iostream>
using namespace std;
typedef int ElemType;

ElemType value;

temp->value = 1;
temp->next = NULL;
Ptrl->next = temp;
for (int i = 2; i <= 10; i++) {
a->value = i;
a->next = NULL;
temp->next = a;
temp = temp->next;
}
return Ptrl;
}

int j = 0;
while (p) {
p = p->next;
j++;
}
return j;
}

int i = 1;
while (p != NULL && i < K) {
p = p->next;
i++;
}
if (i == K)
return p;
else
return NULL;
}

while (p != NULL && x != p->value)
p = p->next;
return p;
}

if (i == 1) {
s->value = x;
s->next = Ptrl;
return s;
}
p = FindKth(i - 1, Ptrl);
if (p == NULL) {
cout << "参数i错误";
return NULL;
} else {
s->value = x;
s->next = p->next;
p->next = s;
return Ptrl;
}
}

if (i == 1) {
s = Ptrl;
if (Ptrl != NULL)
Ptrl = Ptrl->next;
else
return NULL;
free(s);
return Ptrl;
}
p = FindKth(i - 1, Ptrl);
if (p == NULL) {
cout << "第i个节点不存在";
return NULL;
} else if (p->next == NULL) {
cout << "第i个节点不存在";
return NULL;
} else {
s = p->next;
p->next = s->next;
free(s);
return Ptrl;
}
}