链表的合并
来源:互联网 发布:linux删除非空文件夹 编辑:程序博客网 时间:2024/06/08 19:55
#include<stdio.h>#include<stdlib.h>#include<malloc.h>#define OK 1#define ERROR 0#define OVERFLOW -2typedef int status;typedef int ElemType;typedef struct LNode{ElemType data;struct LNode *next;}LNode,*LinkList;void creatlist(LinkList &L,int n){int i;LinkList p;L=(LinkList)malloc(sizeof(LNode));L->next=NULL;printf("输入%d个数",n);for(i=n;i>0;--i){p=(LinkList)malloc(sizeof(LNode));scanf("%d",&p->data);p->next=L->next;L->next=p;}}void printlist(LinkList &L){ LinkList p;for(p=L->next;p!=NULL;p=p->next){printf("%d",*p);}}void hebing(LinkList &LA, LinkList &LB, LinkList &LC){ LinkList pa; LinkList pb; LinkList pc; pa=LA->next; pb=LB->next; LC=pc=LA; while(pa&&pb) {if(pa->data<=pb->data){pc->next=pa;pc=pa;pa=pa->next;}else{pc->next=pb;pc=pb;pb=pb->next;} } pc->next=pa ? pa : pb;}int main(){int a,b;LinkList LA;LinkList LB;LinkList LC;printf("输入表A的数据个数:\n");scanf("%d",&a);creatlist(LA,a);printf("输入表B的数据个数:\n");scanf("%d",&b);creatlist(LB,b);printlist(LA);printf("\n");printlist(LB);printf("\n"); hebing(LA,LB,LC); printlist(LC);printf("\n");return 0;}
阅读全文
0 0
- 链表的合并
- 链表的合并
- 链表的合并
- 合并有序的链表
- 链表的合并 源码
- 一种链表的合并
- 两个链表的合并
- 有序链表的合并
- 有序链表的合并
- 有序链表的合并
- 有序链表的合并
- 两个链表的合并
- 有序链表的合并
- 13.链表的合并
- 有序链表的合并
- 有序链表的合并
- 链表的合并(先排序在合并)
- 链表的生成与合并
- 用Golang写一个搜索引擎
- JS对象
- Redis命令总结(转)
- 字典、列表、元祖、字符串的综合(1)
- linux
- 链表的合并
- 引用传递(传递对象的引用)
- MySQL查看和修改时区
- js判断手机浏览器并跳转到手机网站
- 文章标题
- 度度熊回家
- NYOJ 求平均成绩
- leetcode 10. Regular Expression Matching
- ubuntu vpn搭建