这是我的代码:
#include <bits/stdc++.h>
using namespace std;
void p(auto v) {
cout << "vector = ";
for (int x: v) cout << x << " ";
cout << endl;
}
void a() {
vector<int> v = {1, 2, 3};
v.clear();
p(v);
}
void b() {
vector<int> v = {1, 2, 3};
v = {};
p(v);
}
void c() {
vector<int> v = {1, 2, 3};
{
vector<int> tmp;
v.swap(tmp);
}
p(v);
}
int main() {
a();
b();
c();
return 0;
}
求问:
1.为什么注释中的代码报错?
2.b函数的写法正确吗?
3.三种方法的时间复杂度。