#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> num_arr1;
int n;
cin >> n;
vector<int> num_arr2(n+1);
vector<int> num_arr3(n+1, 2147000000);
vector<int> copy_arr3(num_arr3);
for(int i=0; i<num_arr2.size(); i++) {
cout << num_arr2[i] << " ";
}
cout << "\n";
for(int i=0; i<num_arr3.size(); i++) {
cout << num_arr3[i] << " ";
}
cout << "\n";
for(int i=0; i<copy_arr3.size(); i++) {
cout << copy_arr3[i] << " ";
}
return 0;
}
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
vector<int> num_arr1;
int n;
cin >> n;
for(int i=0; i<n; i++) {
num_arr1.push_back(n-i);
}
for(int i=0; i<n; i++) {
cout << num_arr1[i] << " ";
}
cout << "\n";
sort(num_arr1.begin(), num_arr1.end());
cout << "오름차순 정렬 : ";
for(int i=0; i<n; i++) {
cout << num_arr1[i] << " ";
}
cout << "\n";
sort(num_arr1.begin(), num_arr1.end(), greater<>());
cout << "내림차순 정렬 : ";
for(int i=0; i<n; i++) {
cout << num_arr1[i] << " ";
}
cout << "\n";
return 0;
}
ex) n=5일때의 출력
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> num_arr4[10];
for(int i=0; i<10; i++) {
num_arr4[i].push_back(i);
}
for(int i=0; i<10; i++) {
cout << "num_arr4[" << i << "] is : ";
for(int j=0; j<num_arr4[i].size(); j++) {
cout << num_arr4[i][j] << " ";
}
cout << "\n";
}
return 0;
}
위와 같이, vector를 배열로 선언하면, 인접리스트와 같은 형태로 사용할 수 있다.
ex) 출력