#include
#include
/*定义链表结点*/
typedef struct st_node {
int value;
struct st_node *next;
} node_t;
/*定义链表*/
typedef struct {
node_t head;
node_t *tail;
} list_t;
/*插入到队列尾部*/
void list_push_back(list_t *l, int value) {
node_t *t = (node_t*)malloc(sizeof(node_t));
t->value = value;
t->next = NULL;
l->tail->next = t;
l->tail = t;
}
/*有序地插入元素*/
void list_push_sort(list_t *l, int value) {
/*找出小于或等于 value 的节点,插入到该节点前面*/
node_t *p = l->head.next, *last = &l->head, *t;
for (; p; last = p, p = p->next) {
if (value <= p->value) {
t = (node_t*)malloc(sizeof(node_t));
t->value = value;
t->next = p;
last->next = t;
return;
}
}
/*如果没有小于或等于 value 的节点,则直接插入到末尾*/
list_push_back(l, value);
}
/*使用数组初始化有序链表*/
void list_init(list_t* l, int* p, int s) {
int i = 0;
l->head.next = NULL;
l->tail = &l->head;
for (; i < s; ++i) {
list_push_sort(l, p[i]);
}
}
/*清空链表*/
void list_clear(list_t *l) {
node_t *p = l->head.next, *t;
while (p) {
t = p;
p = p->next;
free(t);
}
l->head.next = NULL;
l->tail = &l->head;
}
/*合并有序链表*/
void list_merge(list_t *l, list_t *r, list_t *o) {
node_t *pl = l->head.next, *pr = r->head.next;
while (pl || pr) {
if (pl && pr) {
if (pl->value <= pr->value) {
list_push_back(o, pl->value);
pl = pl->next;
} else {
list_push_back(o, pr->value);
pr = pr->next;
}
} else if (pl) {
list_push_back(o, pl->value);
pl = pl->next;
} else {
list_push_back(o, pr->value);
pr = pr->next;
}
}
}
/*删除相同结点*/
void list_duplicate_delete(list_t *l) {
if (&l->head != l->tail) {
node_t *p = l->head.next, *last, *t;
int value = p->value;
last = p;
p = p->next;
while (p) {
if (value == p->value) {
t = p;
last->next = p->next;
p = p->next;
free(t);
} else {
value = p->value;
last = p;
p = p->next;
}
}
}
}
/*打印链表*/
void list_show(char* name, list_t *l) {
node_t *p = l->head.next;
printf("%s: ", name);
for (; p; p = p->next) {
printf("%d, ", p->value);
}
printf("\n");
}
/*主函数*/
void main() {
list_t list1, list2, list3;
int a[] = { 10, 4, 6, 12, 1, 8, 14, 10, 14, 6 };
int b[] = { 7, 11, 6, 1, 13, 5, 1, 14 };
/*所有链表需要初始化后才能使用*/
list_init(&list1, a, sizeof(a) / sizeof(int));
list_init(&list2, b, sizeof(b) / sizeof(int));
list_init(&list3, NULL, 0);
printf("初始值:\n");
list_show("List1", &list1);
list_show("List2", &list2);
list_show("List3", &list3);
/*合并链表*/
list_merge(&list1, &list2, &list3);
printf("合并后:\n");
list_show("List1", &list1);
list_show("List2", &list2);
list_show("List3", &list3);
/*去重复*/
list_duplicate_delete(&list3);
printf("去重复后:\n");
list_show("List1", &list1);
list_show("List2", &list2);
list_show("List3", &list3);
/*所有链表都需要释放空间*/
list_clear(&list1);
list_clear(&list2);
list_clear(&list3);
}
//这可是血汗钱啊.....
1,首先到当地购买USB键盘
2,使用键盘的插口连接笔记本的USB接口(记得是USB接口)
3,键盘插上以后会自动安装好驱动,耐心等待几分钟驱动安装好以后,就可以使用了
4、驱动安装好了以后建议把电脑重启
我还想有的版本