Concept explainers
15.11 LAB: Sorting user IDs C++
Given a main() that reads user IDs (until -1), complete the Quicksort() and Partition() functions to sort the IDs in ascending order using the Quicksort
Ex. If the input is:
kaylasimmsthe output is:
julia
I can only change the //TODO and please answer in C++
#include <string>
#include <
#include <iostream>
using namespace std;
// TODO: Write the partitioning algorithm - pick the middle element as the
// pivot, compare the values using two index variables l and h (low and high),
// initialized to the left and right sides of the current elements being sorted,
// and determine if a swap is necessary
int Partition(vector<string> &userIDs, int i, int k) {
}
// TODO: Write the quicksort algorithm that recursively sorts the low and
// high partitions
void Quicksort(vector<string> &userIDs, int i, int k) {
}
int main(int argc, char* argv[]) {
vector<string> userIDList;
string userID;
cin >> userID;
while (userID != "-1") {
userIDList.push_back(userID);
cin >> userID;
}
// Initial call to quicksort
Quicksort(userIDList, 0, userIDList.size() - 1);
for (size_t i = 0; i < userIDList.size(); ++i) {
cout << userIDList.at(i) << endl;;
}
return 0;
}
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
- 15.11 LAB: Sorting user IDs C++ Given a main() that reads user IDs (until -1), complete the Quicksort() and Partition() functions to sort the IDs in ascending order using the Quicksort algorithm, and output the sorted IDs one per line. Ex. If the input is: kaylasimms julia myron1994 kaylajones -1 the output is: julia kaylajones kaylasimms myron1994 I can only change the //TODO #include <string>#include <vector>#include <iostream> using namespace std; // TODO: Write the partitioning algorithm - pick the middle element as the// pivot, compare the values using two index variables l and h (low and high),// initialized to the left and right sides of the current elements being sorted,// and determine if a swap is necessaryint Partition(vector<string> &userIDs, int i, int k) { } // TODO: Write the quicksort algorithm that recursively sorts the low and// high partitionsvoid Quicksort(vector<string> &userIDs, int i, int k) { } int main(int argc,…arrow_forwardC++ Please Help!arrow_forwardC++ Code: In checkpoint B, you will build on checkpoint A to load (from standard input) a database of individuals and their known counts for several STRs (Short Tandem Repeats). Given a query DNA sequence, you will then check the database to find the name of the individual most likely to have that DNA. You will implement the following functions: /** * Reads from standard input a list of Short Tandem Repeat (STRs) * and their known counts for several individuals * * @param nameSTRs the STRs (eg. AGAT, AATG, TATC) * @param nameIndividuals the names of individuals (eg. Alice, Bob, Charlie) * @param STRcounts the count of the longest consecutive occurrences of each STR in the DNA sequence for each individual * @pre nameSTRs, nameIndividuals, and nameSTRs are empty * @post nameSTRs, nameIndividuals and STRcounts are populated with data read from stdin **/ void readData(vector<string>& nameSTRs, vector<string>& nameIndividuals, vector<vector<int>>&…arrow_forward
- AHPA #11: Changing Grades * * Create a C function (switcher) that will receive a pointer to the finalExams array, using only pointers look for D scores and boost them to C scores. (ouput should be same as picture) #include <stdio.h> void switcher() { } int main(void) { int finalExams[] = {90,82,65,79,67,82,94,64,88,78,92,61,96,83,74}; return 0;}arrow_forwardThis problem comes from Introduction to C++ Programming and Data Structures, 4th Edition (invalid_argument )Listing 6.18 gives the hex2Dec(const string & hexString) function that returns a decimal number from a hex string. Implement the hex2Dec function to throw a invalid_argument exception if the string is not a hex string.Write a test program that prompts the user to enter a hex number as a string and display the number in decimal. If the function throws an exception, display "Not a hex number".arrow_forwardC++ 13.10 Write a function SwapArrayEnds() that swaps the first and last elements of the function's array parameter. Ex: sortArray = {10, 20, 30, 40} becomes {40, 20, 30, 10}. #include <iostream>using namespace std; /* Your solution goes here */ int main() { const int SORT_ARR_SIZE = 4; int sortArray[SORT_ARR_SIZE]; int i; int userNum; for (i = 0; i < SORT_ARR_SIZE; ++i) { cin >> userNum; sortArray[i] = userNum; } SwapArrayEnds(sortArray, SORT_ARR_SIZE); for (i = 0; i < SORT_ARR_SIZE; ++i) { cout << sortArray[i] << " "; } cout << endl; return 0;}arrow_forward
- C++ dont copy codearrow_forwardC++arrow_forward1. Replace the (????) with relevant code to make th eprogram function. Details about the code are given below:(Java as been used) a) This program creates a reference to a file in main() and passes the reference to countWords() countWords(), not main(), reads the file and displays Total lines Total words Average words per line */ package finalexamtakehome1; import java.io.*; /** * * @author sweetkim */ public class Finalexamtakehome1 { // public static void countWords(????) { int lineCount = 0; int wordCount = 0; while (????()) { String line = input.nextLine(); lineCount++; Scanner lineScan = new Scanner(line); while (????()) { String next = lineScan.next(); wordCount++; } } double averageWords = (double) wordCount / lineCount; System.out.println("Total lines = " + lineCount); System.out.println("Total words = " + wordCount); System.out.printf("Average words per line =…arrow_forward
- see image for instructions starter code for Main.java import java.util.*; public class Main { public static boolean checkParen(String s) { //implement this method to return true if grouping symbols match //each other, otherwise return false. /* Type your code here. */ }}arrow_forward6.24 C++ Define a function named SortVector that takes a vector of integers as a parameter. SortVector() modifies the vector parameter by sorting the elements in descending order (highest to lowest). Then write a main program that reads a list of integers from input, stores the integers (starting from the second integer) in a vector, calls SortVector(), and outputs the sorted vector. The first input integer indicates how many numbers are in the list. Ex: If the input is: 5 10 4 39 12 2 the output is: 39,12,10,4,2,arrow_forwardI need a better understading onn solving thi question?arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education