{
struct Node *p; p = head;
printf(\数字:\\n\ if (head != NULL)
do//循环实现输出 {
printf(\ printf(\ \ p = p->next; } while (p != NULL); printf(\ }
//链表的交叉合并算法
struct Node * inter_link(struct Node * chain1, int a, struct Node * chain2, int b) { int temp;
struct Node *head, *p1, *p2, *pos; /*判断a,b大小并合并 */ if (a >= b) {
head = p1 = chain1; p2 = chain2; } else/*b>a*/ {
head = p1 = chain2; p2 = chain1;
temp = a, a = b, b = temp; /*交换a和b*/ }
/*下面把p1的每个元素插在p2相应元素之前,p1长a,p2长b*/ pos = head; /*此时pos指向p1中的第一个元素*/ while (p2 != NULL) {//漂亮,蛇形插入 p1 = p1->next; pos->next = p2; pos = p2;
p2 = p2->next; pos->next = p1; pos = p1; }
return head; }
//对合并好的链表进行排序
void InsertSort(struct Node *p, int m)//排序函数 {
int i, j, t;
struct Node *k; k = p;
for (i = 0; i < m - 1; i++) {
for (j = 0; j < m - i - 1; j++) {
if (p->number > (p->next)->number) { t = p->number;
p->number = (p->next)->number; (p->next)->number = t; }
p = p->next; } p = k; } }
struct Node * delete_link(struct Node *p,int i) //按位删除 { struct Node *q; int j=0;
while(j
if(j==i-1&&p->next) {
q=p->next;
p->next=q->next; free(q); }
else return error; }
struct Node * delete_linkz(struct Node *p,int i)//按值删除 { struct Node *q; struct Node *k; int j=0; int h=0;
while(p&&p->number!=i) p=p->next; j++; if (p) {
while (h
if(h==j-1&&p->next){ k=p->next;
p->next=k->next; free(k); } } else
return error; }
//主函数
int main()//main函数 {
struct Node *p1, *p2; int a; int b; int h; int t; int m;
printf(\请输入第一个链表:\\n\ printf(\输入链表的长度a:\\n\ scanf(\
printf(\请输入链表数据:\ p1 = create(a);
printf(\你刚才输入的第一个链表信息:\\n \ print(p1);
printf(\请输入第二个链表:\\n\ printf(\输入链表的长度b:\\n\ scanf(\
printf(\请输入链表数据:\ p2 = create(b);
printf(\你刚才输入的第二个链表的信息:\\n\ print(p2);
p1 = inter_link(p1, a, p2, b); h = a + b;
printf(\合并后的链表\\n:\ print(p1);
InsertSort(p1, h);
printf(\排序后的链表:\\n\ print(p1);
printf(\请输入链表中你所要删除数据的所在位置:\\n\ scanf(\ delete_link(p1,t);
printf(\链表删除数据后链表的信息:\\n\
print(p1);
printf(\请输入你想要删除的数值:\\n\ scanf(\ delete_linkz(p1,m);
printf(\链表删除数据后链表的信息:\\n\ print(p1); return 0; }六.显示结果
(1)m (2)m>n