Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago