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
Which of the following best explains how the Internet is a fault-tolerant system?
IrinaK [193]

Answer:

A

Explanation:

The Internet is fault-tolerant because cybercriminals can conceal their actions, allowing them the ability to carry out faulty actions without leaving a trace.

This statement is actually the same question I had to answer when in my 2nd year 1st semester in itt.
<3 enjoy

8 0
2 years ago
Read 2 more answers
Which of the following best describes open-source web browsers?
Lostsunrise [7]
<span>Following are some best open source CRM software: Really Simple Systems
</span><span>Bitrix24 Raynet SuiteCRM vTiger 
</span>
is this what you are asking for
4 0
3 years ago
Read 2 more answers
An advertisement on a web site touts that the software for sale enables users to enter typed text, handwritten comments, drawing
Nimfa-mama [501]

It is a note taking software because it indicates in the advertisement that it enables users to enter typed text, handwritten comments, drawings, or sketches anywhere on a page and then save the page.

Therefore, the kind of software this advertisement selling is a Note taking software.

4 0
3 years ago
Write a program that asks the user to enter a whole number then outputs a 0 if the number is even or a 1 if the number is odd. (
12345 [234]

Answer:

What language?

Explanation:

7 0
4 years ago
Stress testing examines the pressures placed on the user during system use in extreme environments.
Masja [62]
False. It tests the software or the system in extreme conditions (such as extremely heavy load).
8 0
3 years ago
Other questions:
  • In statistics, what is the mode of a data set?
    6·2 answers
  • which of these is a placeholder in a document into which variable data is inserted during the process of a mail merge?
    10·2 answers
  • Give an efficient algorithm to find all keys in a min heap that are smaller than a provided valueX. The provided valuedoes notha
    12·1 answer
  • Differences of a desktop computer and a laptop
    13·1 answer
  • Analyze the code and identity the value of variable a,b and c after the code execution. int a=40, b=50, c=60; if(! (a&gt;=40)) b
    15·1 answer
  • FREE BRAINLIEST!!!
    14·2 answers
  • consider l= 5 ,r= 11. you must determine the sum of the values of the function in the range L to R . you have to calculate sum =
    7·1 answer
  • Tamera was responding to a complaint that one of the employees is having problems with the wired network connection on their lap
    8·1 answer
  • Can someone help me and explain
    5·1 answer
  • When investigating the serial position curve, delaying the memory test for 30 seconds
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!