q2) modify the modules presented in this chapter that perform the bubble sort, s
ID: 3687127 • Letter: Q
Question
q2) modify the modules presented in this chapter that perform the bubble sort, selection sort, and insertion sort algorithms on an integer array, such that each module keeps a count of the number of swaps it makes. Then, design an application that uses three identical arrays of at least 20 integers.it should call each module on a different array, and display the number of swaps made by each algorithm (The first question is "design a program that allows the user to enter 20 names into a string array.sort the array in ascending (alphebatical) order and display its contents") I need this in pseudocode and in c++ format
Explanation / Answer
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
int i,j;
string t;
string name[20];
cout << "Enter 20 names : ";
for(i=0; i<20; i++){
cin >> name[i];
}
for(i=1; i<20; i++)
{
for(j=1; j<20; j++)
{
if(strcmp(name[j-1].c_str(), name[j].c_str())>0)
{
t = name[j-1];
name[j-1] = name[j];
name[j] = t;
}
}
}
cout<<"Names in alphabetical order : ";
for(i=0; i<20; i++){
cout << name[i] << endl;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.