当前位置: 首页 > news >正文

兰州拼团网站建设/实训百度搜索引擎的总结

兰州拼团网站建设,实训百度搜索引擎的总结,做学校的网站推广发展前景,新闻投稿平台有哪些顺序表应用5:有序顺序表归并 Time Limit: 100 ms Memory Limit: 880 KiB Submit Statistic Discuss Problem Description 已知顺序表A与B是两个有序的顺序表,其中存放的数据元素皆为普通整型,将A与B表归并为C表,要求C表包含了…

 

 

 

顺序表应用5:有序顺序表归并

Time Limit: 100 ms Memory Limit: 880 KiB

Submit Statistic Discuss

Problem Description

已知顺序表A与B是两个有序的顺序表,其中存放的数据元素皆为普通整型,将A与B表归并为C表,要求C表包含了A、B表里所有元素,并且C表仍然保持有序。

Input

 输入分为三行:
第一行输入m、n(1<=m,n<=10000)的值,即为表A、B的元素个数;
第二行输入m个有序的整数,即为表A的每一个元素;
第三行输入n个有序的整数,即为表B的每一个元素;

Output

 输出为一行,即将表A、B合并为表C后,依次输出表C所存放的元素。

Sample Input

5 3
1 3 5 6 9
2 4 10

Sample Output

1 2 3 4 5 6 9 10

Hint

Source

 

#include <stdio.h>
#include <stdlib.h>
struct st
{int data;struct st *next;
};
int main()
{int n,m,i;struct st *head,*tail,*head2,*q,*p;head=(struct st*)malloc(sizeof(struct st));head->next=NULL;head2=(struct st*)malloc(sizeof(struct st));head2->next=NULL;tail=head;scanf("%d%d",&m,&n);for(i=0; i<m; i++){p=(struct st*)malloc(sizeof(struct st));scanf("%d",&p->data);p->next=NULL;tail->next=p;tail=p;}tail=head2;for(i=0; i<n; i++){p=(struct st*)malloc(sizeof(struct st));scanf("%d",&p->data);p->next=NULL;tail->next=p;tail=p;}p=head->next;q=head2->next;tail=head;while(p&&q){if(p->data<q->data){tail->next=p;tail=p;p=p->next;}else{tail->next=q;tail=q;q=q->next;}}while(p){tail->next=p;tail=p;p=p->next;}while(q){tail->next=q;tail=q;q=q->next;}p=head->next;while(p){printf("%d ",p->data);p=p->next;}printf("\n");return 0;
}

C++

#include <iostream>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<string.h>
#define N 1000010
using namespace std;
typedef struct st
{int data;struct st *next;
} tree;
tree *h1,*h2;
tree *creat(int n)
{tree *h,*tail,*p;h=new tree;h->next=NULL;tail=h;for(int i=0;i<n;i++){p=new tree;cin>>p->data;p->next=NULL;tail->next=p;tail=p;}return h;
}
tree *pre(tree *h1,tree *h2)
{tree *p1,*p2,*tail;p1=h1->next;p2=h2->next;tail=h1;while(p1&&p2){if(p1->data<p2->data){tail->next=p1;tail=p1;p1=p1->next;tail->next=NULL;}else{tail->next=p2;tail=p2;p2=p2->next;tail->next=NULL;}}if(p1)tail->next=p1;else tail->next=p2;return h1;
}
int main()
{int n,m;cin>>n>>m;tree *h,*p;h1=creat(n);h2=creat(m);h=pre(h1,h2);p=h->next;while(p){if(p->next==NULL)printf("%d\n",p->data);else printf("%d ",p->data);p=p->next;}return 0;
}

 

http://www.lbrq.cn/news/1476937.html

相关文章:

  • 专门做ppt的网站斧头/制作一个网站的流程有哪些
  • python 网站开发 sae/河南网站推广
  • 机械公司网站建设/百度推广没有效果怎么办
  • html展示网站源代码/百度一下百度首页官网
  • 企业网站的基本功能有哪些/网络营销前景和现状分析
  • 做淘宝网站用什么软件做/百度站长平台网站提交
  • 企业网站域名注册查询/it培训班大概需要多少钱
  • 如何建设公司门户网站/seo标题生成器
  • 政务系统网站建设/天津seo技术教程
  • 做网站去哪个公司/网站建站价格
  • 个人网站不能做淘宝客/5118网站查询
  • 潍坊企业自助建站系统/百度app安装下载免费
  • 效果图网站有哪些好的/衡阳seo服务
  • 网站模板 阿里/技术教程优化搜索引擎整站
  • 向网站上传文件怎么做/网站案例分析
  • 网站域名变更/互联网登录的网站名
  • 上海在线网站/游戏推广接单平台
  • 临沂市建设工程监理公司网站/电商运营转行后悔了
  • 呼和浩特建站/沈阳网站关键词排名
  • 潮州市建设局官方网站/网站有哪些平台
  • 网站建设 荆州/seo霸屏软件
  • 怎么把园林设计网站做的酷炫/推广引流方法与渠道
  • 网站建设应遵循的原则/外贸网站优化
  • 那个网站做二手设备比较好/友链网
  • 陕西省交通建设集团西长分公司网站/sem是什么品牌
  • 宣传网站建设方案模板下载/网络营销策划案
  • 如何把自己做的网站放到微信上/品牌推广方案范文
  • 大型营销型网站制作/网络营销的作用
  • 国内知名公关公司/快速整站排名seo教程
  • 网站开发流程数据库/杭州推广平台有哪些
  • Vue 详情模块 4
  • LINUX82 shell脚本变量分类;系统变量;变量赋值;四则运算;shell
  • [硬件电路-115]:模拟电路 - 信号处理电路 - 功能放大器工作分类、工作原理、常见芯片
  • jenkins从入门到精通-P1—九五小庞
  • 《软件测试与质量控制》实验报告一 测试用例设计
  • k8s-master03加入集群失败解决方法之一