package homework72;
import java.util.Scanner;
class number
{
public int num;
public number next;
number(int n)
{
num = n;next = null;
}
}
class pointer
{
public number p;
public pointer next;
pointer(number point)
{
p = point;next = null;
}
}
public class homework72
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
pointer head = new pointer(null),now = head;
int n = 0;String input = null;
System.out.println("输入数字:(输入“q”结束输入)");
while(true)
{
try
{
input = in.nextLine();
n = Integer.parseInt(input);
}catch(NumberFormatException e)
{
if(input.equalsIgnoreCase("q")) break;
else continue;
}
now.next = new pointer(new number(n));
now = now.next;
}
head = head.next;
merge(head);
number Now = head.p;
while(Now!=null)
{
System.out.print(Now.num+"\t");
Now = Now.next;
}
}
public static void merge(pointer Head)
{
while(Head!=null&&Head.next!=null)
{
pointer now = Head;
number p1=null,p2=null,Start=null,Now=null;
while(now!=null&&now.next!=null)
{
p1 = now.p;
p2 = now.next.p;
Start = new number(0);
Now = Start;
while(p1!=null&&p2!=null)
{
if(p1.num>p2.num)
{
Now.next = p2;
p2 = p2.next;
}
else
{
Now.next = p1;
p1 = p1.next;
}
Now = Now.next;
}
if(p1==null) Now.next = p2;
else Now.next = p1;
now.p = Start.next;
now.next = now.next.next;
now = now.next;
}
}
}
}
homework72.rar_averagefqg_java
版权申诉
190 浏览量
2022-09-24
10:38:20
上传
评论
收藏 4KB RAR 举报
weixin_42653672
- 粉丝: 93
- 资源: 1万+
最新资源
- 深圳市生态环境局年度声环境质量状况
- 基于TMS320F28335的开关电源模块并联供电系统(电路图+源码)
- C#毕业设计-基于asp.net的MVC网上书店管理系统(源码+数据库+文档).zip
- 肇庆市怀集县应急避难场所统计表信息
- 飞行昆虫机器人 飞行昆虫机器人
- 崩铁2.3(SourlCool版).apk
- 知识蒸馏-基于Pytorch通过匹配训练轨迹进行数据集蒸馏-附项目源码+流程教程-优质项目实战.zip
- 儿童节 python庆祝代码简要介绍-20240601.docx
- 知识蒸馏-基于Pytorch实现的语义分割结构化知识蒸馏算法-附项目源码+流程教程-优质项目实战.zip
- 小白物联网智能家居毕设参考STM32+ESP8266/MQTT+OneNet+UniApp
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0