Created
November 27, 2014 13:47
-
-
Save sandes/19879b740d9c79da4143 to your computer and use it in GitHub Desktop.
Aviso: compilar con gcc-> g++ -std=c++11 -o program.bin expand.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <list> | |
using namespace std; | |
list<int> crear_expand(int n,int m){ | |
list<int> l; int sum=0; | |
while(sum<n){ | |
if((sum+m)>n){ | |
sum+=1; | |
l.push_back(1); | |
}else{ | |
sum+=m; | |
l.push_back(m); | |
} | |
} | |
return l; | |
} | |
void expand(list<int>&l, int m){ | |
list<int> aux,tmp; | |
auto p = l.begin(); | |
while(p!=l.end()){ | |
aux = crear_expand(*p,m); | |
auto q = aux.begin(); | |
while(q!=aux.end()){ | |
tmp.push_back(*q); | |
q++; | |
} | |
p++; | |
} | |
l = tmp; | |
} | |
void display(list<int>&l){ | |
auto p = l.begin(); | |
while(p!=l.end()) cout << *p++ << " "; | |
} | |
int main(int argc, char *argv[]) { | |
list<int> l = {7,2,3,1,4,5}; | |
display(l); | |
cout <<endl; | |
expand(l,2); | |
display(l); | |
/*El display sera L={2,2,2,1,2,2,1,1,2,2,2,2,1}*/ | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment