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
Networking and telecommunications technologies, along with computer hardware, software, data management technology, and the peop
Delvig [45]

Answer:

Option d  Information system

Explanation:

Information system is a system used by an organization to organize and analyze data. The main function of the information system is to generate useful information from the organized data to drive for decision making in an organization. An information system can includes components such as computer hardware, software, network and also the human resources required to manage and implement the system. All these components work together to form a functional information system for an organization.

7 0
3 years ago
Any looping construct can be nested inside another loop is known as
Pavel [41]

Answer:

nested loop

pls mark me as brainliest

4 0
3 years ago
Which of these ia an example of gene flow?
GalinKa [24]

In population genetics, gene flow (also known as gene migration) is the transfer of alleles or genes from one population to another. Migration into or out of a population may be responsible for a marked change in allele frequencies (the proportion of members carrying a particular variant of a gene).

7 0
3 years ago
How many total bits are required for a direct-mapped cache with 128 blocks and a block size of 8 bytes, assuming a 4GB main memo
Marysya12 [62]

Answer:

32

Explanation:

Total bits will be 32 only as address is of 32 bits

(meaning to ask the size of the cache)

7 0
2 years ago
Hellpppppppppppppppp
jonny [76]

Answer:

i can't see your problem

6 0
2 years ago
Read 2 more answers
Other questions:
  • The ____ function sums the numbers in the specified range and then divides the sum by the number of cells with numeric values in
    14·1 answer
  • Through the use of a _____ system, information on prospective, current, and past customers is stored and analyzed for future pla
    15·1 answer
  • A network technician is tasked with designing a firewall to improve security for an existing FTP server that is on the company n
    9·1 answer
  • How many hosts are in each subnet?
    15·1 answer
  • If a*b = 2a - 56, calculate the value of<br>3 * 4​
    14·1 answer
  • What is the keyboard shortcut used to paste previously copied text?
    15·2 answers
  • If you need seamless access to the OS, ________ is better.
    8·1 answer
  • I like the impact that the increasing number of social grants may have on the things mothers​
    14·1 answer
  • Can somebody tell me the Minecraft command to clear an entire world and destroy every block if u Dunno please don’t answer &gt;-
    13·1 answer
  • What is an automatic update and when should you use it
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!