在做题中再次回顾了一些细节,那就写下来吧:
有向图的实现:A矩阵:M[i][j]==1;表示i->j.
矩阵的缺点是浪费空间
B链表:
选择排序函数:findMaxPos(int arr[ ],int n) selectionSort(int arr[ ],int n)]
插入排序Insertion Sort:把后面乱序的拿出来插入前面有序的数组中: void insert(int arr[ ],int n)
----------------------------
buf缓冲器
使用cin从标准输入读取数据时,通常用到的方法有cin>>,cin.get,cin.getline。
不想略过空白字符,那就使用 noskipws 流控制。比如cin>>noskipws>>input;
- getline函数声明在< string>头文件中。cin.getline(array,20); //或者指定结束符,使用下面一行
getline(cin,str) 原型:
istream& getline ( istream& is, string& str);//默认以换行符结束
istream& getline ( istream& is, string& str, char delim);
cin.getline()类似,但是cin.getline()属于istream流,而getline()属于string流,是不一样的两个函数。
stringstream: void str() //无参形式,用于将stringstream流中的数据以string字符串的形式输出.cout<<ss.str()
stringstream通常是用来做数据转换的,用于字符串与其他变量类型的转换:
string str1("How are you? 123 1 4.368"); stringstream ss(str1);//构造函数初始化
tmp暂时,是一个用来备份的名字
ans是answer的缩写,给解决方案命名
0为false,1为true。
//swap1(&a,&b); void swap1(int* a,int *b)
//swap2(a,b); void swap2(int& a,int& b) 地址传递
//swap3(&a,&b); void swap3(int* a,int *b) 引用传递