Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <list>
- #include <iostream>
- int main() {
- std::list<int> lista;
- if (lista.size() == 0 && lista.empty()){
- lista.push_back(2);
- lista.push_back(3);
- lista.push_back(4);
- lista.push_back(5);
- lista.push_back(6);
- lista.push_back(7);
- lista.push_front(1);
- lista.push_front(0);
- }
- std::list<int>::iterator it = lista.begin();
- int contador = 0;
- while (it != lista.end()) {
- if (contador != *it) {
- std::cout << "MAL!\n";
- }
- it++;
- contador++;
- }
- while (it != lista.begin()) {
- if (contador != *it) {
- std::cout << "MAL!\n";
- }
- it--;
- contador--;
- }
- std::list<int> aux;
- // Me quedo con los valores pares.
- while (it != lista.end()) {
- if (*it % 2 == 0) {
- aux.push_back(*it);
- }
- it++;
- }
- lista.swap(aux);
- it = lista.begin();
- while (it != lista.end()) {
- std::cout << *it << '\n';
- it++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement