17th Week Project 2--Reference as a row parameter (three-digit ordering (reference type as parameter))

Source: Internet
Author: User

/* Copyright (c) 2014, Yantai University School of Computer * All rights reserved. * File name: Test.cpp *:    Liu Chang * completion date: 2014  monthly  * Version number: v1.0 * * Problem Description: Design a program, enter three integers, order it from large to small output, require (1) sorting function With the function implementation, three integers with three variables, do not have to define the array, (2) write two versions of the function, one takes the address value of the method, and the other takes the reference type as parameters. * Input Description: Three integers, * program output: This three integers from large to small output.

#include <iostream>using namespace std;void Exchange (int &q1,int &q2,int &q3), void swap (int &p1, int &p2); int main () {    int a,b,c;    cin>>a>>b>>c;    Exchange (A,B,C);    cout<<a<< "<<b<<" "<<C;} void Exchange (int &q1,int &q2,int &q3) {    if (Q1<Q2)        swap (Q1,Q2);    if (Q1<Q3)        swap (Q1,Q3);    if (Q2<Q3)        swap (Q2,Q3);} void swap (int &p1,int &p2) {    int temp;    TEMP=P1;    P1=P2;    P2=temp;}

Operation Result:



Learning experience:

Well, originally was ready to ask the teacher how to use, but did not think of a book on the books there are examples Ah, according to the reference type as an example of parameters or completed the project, it seems to be too dependent on the teacher, I was wrong.

17th Week Project 2--Reference as a row parameter (three-digit ordering (reference type as parameter))

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.