새로새록
[c++]11.오름차순 정렬 함수 본문
#include <iostream>
#include <vector>
#include <string>
using namespace std;
template <class T>
void sort(vector<T>& type) {
for (int i = 0; i < size(type) - 1; i++) {
for (int j = 0; j < size(type) - (i + 1); j++) {
if (type[j] > type[j + 1]) {
T temp = type[j];
type[j] = type[j + 1];
type[j + 1] = temp;
}
}
}
}
template <class T>
void print(T type) {
auto e = end(type);
for (auto i=begin(type); i != e; i++)
cout << *i << ", ";
cout << endl;
}
int main(){
vector<int> int_list(5);
int_list = { 10,5,8,1,3 };
vector<double> double_list(5);
double_list = { 10.1,5.1,8.1,1.1,3.1 };
vector<string> string_list(5);
string_list = { "하나","둘","셋","넷","다섯" };
sort(int_list);
sort(double_list);
sort(string_list);
print(int_list);
print(double_list);
print(string_list);
}
'소프트웨어융합 > 경희대 c++ 과제' 카테고리의 다른 글
[c++]11. 회문 판별 - 람다함수 (0) | 2020.07.18 |
---|---|
[c++]11. 홀수와 n*n 마방진 (0) | 2020.07.18 |
[c++]10.리스트 추가 삭제 출력 (0) | 2020.07.18 |
[c++]10. 두 벡터의 곱 max min (0) | 2020.07.18 |
[c++]9. stack class (0) | 2020.07.17 |