1. arrays in C ++ serve as three form parameter Methods passed by actual parameters
# Include <iostream>
Using namespace STD;
Void change (Int & A, int B) {// by reference, the reference is the alias of the original variable, and the return of the variable value will be affected.
A = 5;
}
Void Change1 (int * a, int B) {// pass through the pointer, the variable value will be affected when returned
* A = 0;
}
Void Change2 (int A, int B) {// The returned variable value will not be affected.
A = 2;
}
Int main (){
Int c = 6, D = 4;
Change (c, d); // directly pass the variable
Cout <C <Endl;
Change1 (& c, d); // transfer the variable address
Cout <C <Endl;
Change2 (c, d); // pass the variable
Cout <C <Endl;
Return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2. The priority queue in C ++ is a large heap by default. It is customized as a small heap. Note: How to reload the opertor <function.
/* Reload operator in the struct structure <Function
# Include <iostream>
# Include <string>
# Include <queue>
Using namespace STD;
Struct SS {
String name;
Double score;
// Operator of the custom struct element type <overload function, so that the small element is placed in the first line of the queue in the priority queue
// Return true to the backend
Friend bool operator <(const SS & A, const SS & B) {return a. score> B. Score;
}
};
Int main (){
Struct ss stu [] ={{ "suting", 120.0 },{ "Xiaowang", 123.0 },{ "Xiaoli", 110 }};
Priority_queue <SS> q;
For (INT I = 0; I <sizeof STU/sizeof STU [0]; I ++)
Q. Push (STU [I]);
Cout <q. Top (). Name <Endl;
}
*/