C++mid104_3
user_3763047219
c_cpp
3 years ago
821 B
5
Indexable
#include <iostream>
template<typename x>
void sortpair(x &a, x &b){
if(a>b){
x c = a;
a = b;
b = c;
}
}
template<typename y>
void sortt(y list[6]){
for(int i = 0; i<5; i++){
for(int j=i+1; j<6; j++){
sortpair(list[i],list[j]);
}
}
}
template<typename z>
void print(z list[6]){
for(int i=0;i<6;i++){
std::cout<<list[i]<<"";
}
std::cout<<std::endl;
}
int main(){
int intlist[6] = {3,5,2,7,1,9};
double doublelist[6] = {1.3, 2.4, 7.2, 9, 3.3, 5.1};
char charlist[6] = {'b','u','d','a','w','k'};
//std::cout<<doublelist<<std::endl;
sortt(intlist);
sortt(doublelist);
sortt(charlist);
print(intlist);
print(doublelist);
print(charlist);
return 0;
}Editor is loading...