17th Week Item 2--Reference as a row parameter (three-digit ordering (pointer 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 *num1,*num2,*num3,a,b,c;    cin>>a>>b>>c;    num1=&a;    num2=&b;    num3=&c;    Exchange (NUM1,NUM2,NUM3);    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:

Pointer to the most basic form of writing the feeling has mastered, but still do not understand the usefulness of pointers, can improve efficiency but do not know how to improve, but also to read more reading AH.

There is also a reference to the version of the parameters of the class will not, until tomorrow to ask the teacher to fill up. Ask the great God to first point to the reference type to do the parameter is how to apply?

17th Week Item 2--Reference as a row parameter (three-digit ordering (pointer 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.