Professional Documents
Culture Documents
Prepared by,
J. K. Josephine Julina
SSN College of Engineering, Kalavakkam – 603 110
Department of Information Technology
cout<<vin[j]<<"\t";
cout<<"\nInsert -1 at the beginning"<<"\n";
vin.insert(vin.begin(),-1);
for(j=0;j<vin.size();j++)
cout<<vin[j]<<"\t";
cout<<"\nInsert data 40 Index 4"<<"\n";
vin.insert(vin.begin()+4,40);
for(j=0;j<vin.size();j++)
cout<<vin[j]<<"\t";
cout<<"\nErase data at position 2: "<<"\n";
vin.erase(vin.begin()+2);
for(j=0;j<vin.size();j++)
cout<<vin[j]<<"\t";
cout<<"\nStatus 1 for empty is true ie. Empty, 0-empty is false ie. Not empty";
cout<<"\n"<<vin.empty();
cout<<"\nAfter using clear command: ";
vin.clear();
cout<<"\n"<<vin.empty();
return 0;
}
10 50
5 10 50 100
100
100
50
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> vin;
vin.push_back(10);
vin.push_back(50);
for(int i=0; i<vin.size(); i++)
cout<<vin.at(i)<<"\t";
vin.insert(vin.begin(),5);
vin.push_back(100);
cout<<"\n";
vector<int>::iterator it;
for (it=vin.begin(); it<vin.end(); it++)
Prepared by,
J. K. Josephine Julina
SSN College of Engineering, Kalavakkam – 603 110
Department of Information Technology
cout<<*it<<"\t";
it=vin.begin();
advance(it, 3);
cout<<"\n"<<*it<<"\n";
vector<int>::iterator btr = vin.begin();
vector<int>::iterator etr = vin.end();
auto ait = next(btr, 3);
auto ait1 = prev(etr, 2);
cout << *ait <<"\n";
cout << *ait1 <<"\n ";
return 0;
}
5. c Write a program to find the product of two matrices using vectors and iterators.
Try it!
Prepared by,
J. K. Josephine Julina