/* 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))