-
-
Save parzibyte/5cd3c44a13e5e40807b161de6740e52e to your computer and use it in GitHub Desktop.
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 <vector> | |
int main() { | |
std::vector<int> numeros; | |
// Se agregan al final con push_back | |
numeros.push_back(50); | |
numeros.push_back(70); | |
numeros.push_back(80); | |
// Imprimirlos para ver contenido | |
std::cout << "Imprimiendo" << std::endl; | |
for (std::size_t i = 0; i < numeros.size(); i++) { | |
std::cout << numeros[i] << std::endl; | |
} | |
// Ahora con insert. | |
// Insertar al inicio | |
numeros.insert(numeros.begin(), 100); | |
// Insertar en la posición 1 | |
numeros.insert(numeros.begin() + 1, 500); | |
// Insertar en la penúltima posición | |
numeros.insert(numeros.end() - 1, 1000); | |
// Imprimirlos para ver contenido | |
std::cout << "Imprimiendo" << std::endl; | |
for (std::size_t i = 0; i < numeros.size(); i++) { | |
std::cout << numeros[i] << std::endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment