Sort function Overloading

Source: Internet
Author: User

Topic content:

Write a set of overloaded sorting functions that can order two integers, three integers, four integers, and integer arrays from large to small, with the function named sort, where the array sort should use the recursive method, and the print function to display the sorted array elements on one line.

The main functions are as follows:

int main ()

{

int a,b,c,d;

int data[100];

int k,n,i;

cin>>k;

Switch (k)

{

Case 1:

cin>>a>>b;

Sort (A, b);

cout<<a<< "" <<b<<endl;

Break

Case 2:

cin>>a>>b>>c;

Sort (a,b,c);

cout<<a<< "" <<b<< "" <<c<<endl;

Break

Case 3:

cin>>a>>b>>c>>d;

Sort (a,b,c,d);

cout<<a<< "<<b<<" "<<c<<" "<<d<<endl;

Break

Case 4:

cin>>n;

for (i=0;i<n;i++)

{

cin>>data[i];

}

Sort (data,n);

Print (data,n);

Break

}

return 0;

}

Input format:

Please analyze yourself according to the main program.

Output format:

Sorted data, one row, from large to small, with no spaces at the end.

Input Sample:

4

10

22 15 20 16 3 27 14 64 108 10

Sample output:

108 64 27 22 20 16 15 14 10 3

Please submit the complete program, including the given main ()

Sort function Overloading

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.