C++ 排序应用程序

706 篇文章 ¥99.90 ¥299.90
80 篇文章
本文深入探讨了C++中实现各种排序算法的详细步骤,包括快速排序、归并排序和插入排序等经典算法,同时讲解了它们的时间复杂度和适用场景。通过对这些排序算法的实践,帮助开发者提升在C++编程中的效率和能力。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<iostream>
#include <vector>
#include <functional>   // std::greater
#include <algorithm>    // std::sort

using namespace std;

int main(void)
{
	int a;
	char type='a';
	vector<int> vec;

	cout << "请输入数字序列,最后一个数字回车结束," << endl;

	while (cin >> a) {
		//cout << a << endl;
		vec.push_back(a);
		if (cin.get() == '\n') break;
	}
	cout << endl;

	cout << "请输入排序类别,a-升序, d-降序" << endl;
	cin >> type;
	cout << endl;

	if (type == 'a')
	{
		sort(vec.begin(), vec.end());   //默认升序
	}

	if (type == 'd')
	{
		std::sort(vec.begin(), vec.end(), std::greater<int>());
	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值