Standard Templete Library in CPP
Hello everyone
Welcome to our another blog. In this blog i code for some Standard Templete Library(STL) which will help you to coding practice.
All the best !!
Keep Practicing!!
#include <iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
vector<int> v; //Defining vector v
v.push_back(1);
v.push_back(5); //Inserting element in vector
v.push_back(8);
v.push_back(9);
cout<<"Finding 5 -> "<<binary_search(v.begin(), v.end(), 5)<<endl;
//Applyin binary search for 5
cout<<"lower bound -> "<<lower_bound(v.begin(),v.end(),5)-v.begin()<<endl;
//finding lower bond for 5
cout<<"uper bound -> "<<upper_bound(v.begin(), v.end(),5)-v.begin()<<endl;
//finding upper bond for 5 int a =4;
int b = 8;
cout<<"maximum -> "<<max(a,b)<<endl; //finding maximum value
cout<<"minimum -> "<<min(a,b)<<endl; //finding minimum value
swap(a,b);
cout<<endl<<"a -> "<<a<<endl;
string ab = "abcd efgh";
reverse(ab.begin(), ab.end());
cout<<"Stirng -> "<<ab<<endl; //o/p-> hgfe dcba
rotate(v.begin(), v.begin()+1, v.end());
cout<<"After Rotate -> "<<endl; //o/p-> rotate by one of the above vector
for(int i:v){
cout<<i<<" ";
}
}
Comments
Post a Comment