typedef struct node {
int val;
struct node* next;
}Node,*linklist;
以上为结构体:
1.写一个返回尾指针的函数列如
linklist findp(Node* L) {
Node* s;
s = L->next;
while (s->next != L ) {
s = s->next;
}
return s;
}
注意:此函数中 return前的 t->text ......变成 t->text=L->next 会使寻找;尾节点;的函数进入循环
linklist headlist(Node* L) {
L->next = NULL;
int nums[4] = { 4,5,1,9 };
Node* s;
for (int i = 0; i < 4; i++) {
s= (Node*)malloc(sizeof(Node));
s->val = nums[i];
s->next = L->next;
L->next = s;
}
Node* t;
t = (Node*)malloc(sizeof(Node));
t = L->next;
while (t->next != NULL) {
t = t->next;
}
t->next = L;
return L;
}
合并链表函数如下:
linklist connectlist(Node* Ta, Node* Tb) {
Node* r1, * r2;
r1 = findp(Ta);
r2 = findp(Tb);
Node* p;
p = r1->next;
r1->next = r2->next->next;
free(r2->next);
r2->next = p->next;
return Ta;
}
m=connectlist(Ta, Tb);