Question
#include #include #include #include #include using namespace std; template void binarysearch( vector a , T x ) { int i = 0; int j =
#include
#include
#include
#include
#include
using namespace std;
template
void binarysearch( vector
{
int i = 0;
int j = a.size() - 1;
int m;
while( i <= j )
{
m = (i + j) / 2;
if( a[m] == x )
break;
else if( a[m] < x )
i = m + 1;
else
j = m - 1;
}
if( a[m] == x )
cout< else cout< } template void display(vector { cout<<"Vector elements : "; int i; for( i = 0 ; i < arr.size() ; i++ ) cout< cout<<" "; } int main() { vector while(1) { cout<<"Enter your choice ... "; cout<<"1. add element "; cout<<"2. delete element "; cout<<"3. search "; cout<<"4. quit "; int choice; cin>>choice; int x , i; switch(choice) { case 1 : cout<<"Enter the element to add : "; cin>>x; arr.push_back(x); sort( arr.begin() , arr.end() ); display(arr); break; case 2 : cout<<"Enter the element to remove : "; cin>>x; for( i = 0 ; i < arr.size() ; i++ ) if( arr[i] == x ) arr.erase(arr.begin() + i); cout<<"Removed successfully "; display(arr); break; case 3 : cout<<"Enter the element to search : "; cin>>x; binarysearch(arr ,x ); case 4 : exit(0); } } return 0; } vector i don't know why i am getting error in my code
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started