subject

// Binary String Search and Selection Sort #include
#include
using namespace std;
// Function prototypes
void selectionSort(string[], int);
void displayArray(string[], int);
int binarySearch(string[], int, string);
int main()
{
const int NUM_NAMES = 20;
string search;
string names[NUM_NAMES] = { "Collins, Bill", "Smith, Bart", "Allen, Jim",
"Griffin, Jim", "Stamey, Marty", "Rose, Geri",
"Taylor, Terri", "Johnson, Jill",
"Allison, Jeff", "Looney, Joe", "Wolfe, Bill",
"James, Jean", "Weaver, Jim", "Pore, Bob",
"Rutherford, Greg", "Javens, Renee",
"Harrison, Rose", "Setzer, Cathy",
"Pike, Gordon", "Holland, Beth" };
// Sort the array.
selectionSort(names, NUM_NAMES);
// Display the sorted array.
cout << "Here are the names sorted:\n";
cout << "\n";
displayArray(names, NUM_NAMES);
// Get a name to search for.
cout << "Enter a name to search for: ";
getline(cin, search);
// Search for the name.
int results = binarySearch(names, NUM_NAMES, search);
// If results contains -1 the string was not found.
if (results == -1)
cout << "That names does not exist in the array.\n";
else
{
// Otherwise results contains the subscript of
// the specified name in the array.
cout << "That name is found at element " << results;
cout << " in the array.\n";
}

return 0;
}
//
// The selectionSort function performs an ascending order *
// selection sort on an array of strings. The size *
// parameter is the number of elements in the array. *
//
void selectionSort(string values[], int size)
{
int startScan;
int minIndex;
string minValue;
for (startScan = 0; startScan < (size - 1); startScan++)
{
minIndex = startScan;
minValue = values[minIndex];
// key fill in the index bounds
for (int index = key; index < key; index++)
{
// key what operator?
if (values[index] key minValue)
{
minValue = values[index];
minIndex = index;
}
}

values[minIndex] = values[startScan];
values[startScan] = minValue;
}
}
//
// The displayArray function displays the contents of *
// the array. *
//
void displayArray(string values[], int size)
{
for (int i = 0; i < size; i++)
cout << values[i] << endl;
}
//
// The binarySearch function performs a binary search on *
// an array of strings. array, which has a maximum of *
// size elements, is searched for the string stored in *
// value. If the string is found, its array subscript is *
// returned. Otherwise, -1 is returned indicating the *
// string was not in the array. *
//
int binarySearch(string values[], int size, string value)
{
bool found = false; // Flag, initialized to false.
int first = 0; // To hold the first array element
int middle; // To hold the mid point of search
int last = size - 1; // To hold the last array element
int position = -1; // To hold the position of search value
while (!found && first <= last)
{
// Calculate the mid point.
// key
middle = key
// Determine if the value is found at the mid point.
if (values[middle] == value)
{
position = middle;
found = true;
}
// Determine if the value is in the lower half.
// key add the comparison operator here
else if (values[middle] key value)
// key
last = key
// Determine if the value is in the upper half.
else
// key
first = key
}
return position;
}
complete the marked key

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 04:50, edenlbarfield
Which are steps taken to diagnose a computer problem? a) reproducing the problem and using error codes b) reproducing the problem and troubleshooting c) using error codes and troubleshooting d) using error codes and stepping functions
Answers: 1
image
Computers and Technology, 22.06.2019 12:30, Machuco127
Some of the first computer games were created in the early 1970s by college students experimenting after hours to see what the were capable of doing.
Answers: 3
image
Computers and Technology, 22.06.2019 22:00, lgary9462
Perform the following tasks: a. create a class named testclass that holds a single private integer field and a public constructor. the only statement in the constructor is one that displays the message “constructing”. write a main()function that instantiates one object of the testclass. save the file as testclass. cpp in the chapter 08 folder. run the program and observe the results. b. write another main()function that instantiates an array of 10 testclass objects. save the file as test class array. c . run this program and observe the results.
Answers: 1
image
Computers and Technology, 24.06.2019 03:30, live4dramaoy0yf9
Explain the importance of html in web page designing in 20 sentences..
Answers: 1
You know the right answer?
// Binary String Search and Selection Sort #include
#include
using namespace std;

Questions in other subjects:

Konu
Mathematics, 29.03.2021 18:50
Konu
Mathematics, 29.03.2021 18:50