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 a , T x )

{

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 arr)

{

cout<<"Vector elements : ";

int i;

for( i = 0 ; i < arr.size() ; i++ )

cout<

cout<<" ";

}

int main()

{

vector arr;

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 arr; Implicit instantiation of undefined template 'std::__1::vector >'

i don't know why i am getting error in my code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!