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>
using namespace std;
struct ss{
string name;
double score;
//自定义struct元素类型的operator<重载函数,使得优先队列中,将小元素放在队列的首部
//返回true的排在后面
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;
}
*/