1、C++中数组作为实际参数传递的三种形式参数方法
#include<iostream>
using namespace std;
void change(int& a,int b){ //通过引用,引用是原变量的别名,变量值返回时会受影响
a=5;
}
void change1(int* a,int b){ //通过指针进行传递,变量值返回时会受影响
*a=0;
}
void change2(int a,int b) { //变量值返回时不会受影响
a=2;
}
int main(){
int c=6,d=4;
change(c,d); //直接传递变量
cout<<c<<endl;
change1(&c,d); //传递变量地址
cout<<c<<endl;
change2(c,d); //传递变量
cout<<c<<endl;
return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2、C++中的优先队列,默认是大堆,自定义为小堆,注意:如何重载opertor<函数。
/* 在struct结构中重载operator< 函数
#include<iostream>
#include<string>
#include<queue>