Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // constructing vectors
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- void showVector(vector<int> vec) {
- for (vector<int>::iterator it = vec.begin(); it != vec.end(); ++it) {
- cout << ' ' << *it;
- }
- cout << '\n';
- }
- void inverseVec(vector<int> vec) {
- }
- int main ()
- {
- int myints[] = {16,2,77,29};
- vector<int> myVec (myints, myints + sizeof(myints) / sizeof(int) );
- myVec.push_back(-2);
- cout << "The contents of fifth are:";
- // 1st way of printig
- for(int i = 0; i < myVec.size(); i++) {
- cout << myVec[i] << ' ';
- }
- cout << endl;
- // Sorting
- sort(myVec.begin(), myVec.end());
- cout << "Sorted vector is:";
- // 2nd way of printing
- showVector(myVec);
- // Pop out
- cout << "Lets see the pop back";
- myVec.pop_back();
- showVector(myVec);
- // Find
- vector<int>::iterator it = find(myVec.begin(), myVec.end(), 29);
- if(it == myVec.end()) {
- cout << "Nu am gasit elementul" << endl;
- } else {
- cout << "Am gasit elementul " << *it << " la pozitia: " << it - myVec.begin() << endl;
- }
- inverseVec(myVec);
- showVector(myVec);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement