1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
melomori [17]
3 years ago
7

Write a program that sorts a vector of names alphabetically using the selection sort and then searches the vector for a specific

name using binary search. To do that, you need to write three functions: 1. void selSort (vector & v): sorts the vector using selection sort 2. void display (const vector & v): displays the vector contents 3. int binSearch (const vector & v, string key): searches the vector for a key, returns the index of the key if found and -1 if the index is not found
Computers and Technology
1 answer:
Natalka [10]3 years ago
7 0

Answer:

See Explaination

Explanation:

#include <iostream>

#include <iomanip>

#include <vector>

using namespace std;

// Function Declarations

void display(vector<string> names);

void selectionSort(vector<string>& names);

int binarySearch(vector<string> names, string name);

int main()

{

string search;

vector<string> names{ "Joe Garcia", "Amelia Perez", "Bob Haynes", "Tim Ducrest", "Kevin Garcia", "Suzy Walter", "Fang Yi", "Robert James", "Mary Andres" };

cout << "__Displaying names before sort__" << endl;

display(names);

selectionSort(names);

cout << "__Displaying names after sort__" << endl;

display(names);

search = "Kevin Garcia";

int b1 = binarySearch(names, search);

if (b1 != -1) {

cout << search << " is found in the vector" << endl;

}

else {

cout << search << " is not found in the vector" << endl;

}

search = "Joe James";

b1 = binarySearch(names, search);

if (b1 != -1) {

cout << search << " is found in the vector" << endl;

}

else {

cout << search << " is not found in the vector" << endl;

}

return 0;

}

//This function will the Vector elements

void display(vector<string> names)

{

for (int i = 0; i < names.size(); i++) {

cout << names[i] << endl;

}

}

//This function will sort the Vector in ascending order

void selectionSort(vector<string>& names)

{

int start;

string temp;

for (int i = names.size() - 1; i > 0; --i) {

start = 0;

for (int j = 1; j <= i; ++j) {

if (names[j].compare(names[start]) > 0) {

start = j;

}

temp = names[start];

names[start] = names[i];

names[i] = temp;

}

}

}

//This function will search for a string in vector

int binarySearch(vector<string> names, string name)

{

int first = 0,

last = names.size() - 1,

middle,

position = -1;

bool found = false;

while (!found && first <= last)

{

middle = (first + last) / 2;

if (names[middle] == name)

{

found = true;

position = middle;

}

else if (names[middle] > name)

last = middle - 1;

else

first = middle + 1;

}

return position;

}

You might be interested in
Fred has to write a report on the general opinion of the influence of television on political decision-making. What internet res
Amiraneli [1.4K]
B. forum
they hold the most accurate information and people respond the most
3 0
3 years ago
Read 2 more answers
Matt goes to an Internet café and tries to access his emails. The email client asks Matt to enter his email address along with t
Radda [10]

Answer:

acknowledging

Explanation:

it has to be d

6 0
3 years ago
For your biology class, you will be giving a presentation of the findings of a plant
kaheart [24]

Answer:

PowerPoint

Explanation:

It is dedicated for presentation.

5 0
3 years ago
Read 2 more answers
Write a program that prompts the user to input two numbers, a numerator and a divisor. Your program should then divide the numer
12345 [234]
What language? JavaScript? Python?
8 0
3 years ago
Read 2 more answers
The second version of css, css2, was introduced in 1998, expanding the language to provide styles to _________.
Evgen [1.6K]

Answer:

Structured Documents

Explanation:

Structured Documents consist of hierarchy in the files. They may include data files. HTML (Hyper-text markup language) documents and XML (Extensible Markup Language) applications are the examples of Structured Documents.

6 0
3 years ago
Other questions:
  • 5. What would the browser display if the following code were executed in a script?a var product = 0; while ( product &lt;= 25 );
    8·1 answer
  • Which WAN technology is designed to work with a variety of commonly used layer-2 protocols and is sometimes called a layer-2.5 t
    15·1 answer
  • What command is used to add a reflection or an outline to text
    7·1 answer
  • What should be used to clean LCD monitors? Liquid window cleaner Ammonia wipes Windshield washer liquid Antistatic monitor wipes
    15·1 answer
  • What is an identified component of a software program that might allow a hacker or other intruder to gain entry and control of a
    10·2 answers
  • A(n) ____ is a grouping of related objects within a domain,
    15·1 answer
  • 1. provide at least 3 properties and 3 methods of the object computer.
    8·1 answer
  • 10. What is "bandwidth"? (
    15·1 answer
  • AYYOOOO CAN YOU HELP A GIRL OUUTT???
    11·1 answer
  • PL I BEG YOU HELP
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!