1020: 两整数排序

54 篇文章 3 订阅

使用C++编写程序:

题目描述

从键盘输入两个整数x,y,按从小到大的顺序输出它们的值。

输入

输入两个整数x,y。

输出

按从小到大的顺序输出它们的值。数据之间以空格间隔。

样例输入 Copy

20 16

样例输出 Copy

16 20

程序代码如下:
#include<iostream>
#include<algorithm>
#define ElemType int
#define MaxSize 2

using namespace std;

class AscendingSort
{
public:
	AscendingSort(ElemType N[]);
	void GetResult();
private:
	ElemType Num[MaxSize];
};

inline AscendingSort::AscendingSort(ElemType N[])
{
	for (int i = 0; i < MaxSize; i++)
		Num[i] = N[i];
}

inline void AscendingSort::GetResult()
{
	stable_sort(Num, Num + MaxSize);                     //对给定区间所有元素进行稳定排序
	for (int i = 0; i < MaxSize; i++)
		cout << Num[i] << " ";
}

int main()
{
	ElemType Number[MaxSize];
	for (int i = 0; i < MaxSize; i++)
		cin >> Number[i];
	AscendingSort AS(Number);
	AS.GetResult();
	return 0;
}
程序运行结果如下:

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值