-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ejercicio3.h
44 lines (36 loc) · 939 Bytes
/
Ejercicio3.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#ifndef EJERCICIOS_EJERCICIO3_H
#define EJERCICIOS_EJERCICIO3_H
using namespace std;
template<template<typename...>class container, typename T>
container<T> Sumar_rango(container<T> v1, container<T> v2){
container<T> vr;
int pos = 0;
int cont;
container<T> max;
container<T> min;
if(v1.size() == v2.size()){
for(auto it=begin(v1);it != end(v1); it++){
vr.push_back(*it+v2[pos++]);
}
}else{
if(v1.size() > v2.size()) {
max = v1;
min = v2;
} else {
max = v2;
min = v1;
}
for(auto i=0;i<max.size();i++){
if(cont<min.size()) {
vr.push_back(max[i] + min[cont++]);
}
else{
cont = 0;
vr.push_back(max[i]+min[cont++]);
}
}
}
return vr;
}
#endif //EJERCICIOS_EJERCICIO3_H