升序C ++

时间:2018-10-18 19:44:51

标签: c++

我遇到了一个函数定义,该函数定义用于按升序和从何处开始对数字进行排序。它只有三个数字,所以我最好做if语句或数组吗?

#include<iostream>
#include<array>  //if I wish to use an array

using namespace std;

//Function defintion for sortie goes here 
void sortie(int first, int second, int third)

int main()
{
    cout << "Enter three numbers ";
    int first, second, third;
    cin >> first >> second >> third;
    cout << endl;
    cout << "Unsorted: " << first << ", " << second << ", " << third << endl;
    sortie(first, second, third);  //the function is being called here 
    cout << "Sorted:   " << first << ", " << second << ", " << third << endl;
    return 0;
}

1 个答案:

答案 0 :(得分:2)

您需要更改参数,因此原型将为:

void sortie(int& first, int& second, int& third);

然后只用一些swap来订购它们。