Question

In: Computer Science

MUST BE DONE IN C++ Use qsort( ) function in Visual Studio to sort the following...

MUST BE DONE IN C++

Use qsort( ) function in Visual Studio to sort the following three arrays:

int array1 [] = { 3, 4, 2, 1, 7};

float array2 [] = {0.3, 0.1, 5.5, 4.3, 7.8};

char array3 [] = {‘c’, ‘d’, ‘a’, ‘b’, ‘f’};

                                   

Develop a driver function to print out the sorted results and put the screenshot into the

word document.

Note that you have to use qsort( ) provided by Visual Studio.

What is the time complexity of quick sort?

Solutions

Expert Solution

RUN THIS IN VISUAL STUDIO, IT WILL GIVE THE SAME OUTPUT

#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int compare(const void* a, const void* b)
{
const int* x = (int*) a;
const int* y = (int*) b;

if (*x > *y)
return 1;
else if (*x < *y)
return -1;

return 0;
}

int cmpfunc( const void *a, const void *b) {
return *(char*)a - *(char*)b;
}

int main(int argc, char const *argv[])
{
int array1 [] = { 3, 4, 2, 1, 7};
float array2 [] = {0.3, 0.1, 5.5, 4.3, 7.8};
char array3 [] = {'c', 'd', 'a', 'b', 'f'};

clock_t time;
time = clock();
qsort(array1, 5, sizeof(int), compare);
time = clock() -time;
for(int i=0 ;i<5;i++)
cout<<array1[i]<<" ";
cout<<endl;
cout<<"Time for array1 - "<<time<<endl<<endl;

time = clock();
qsort(array2, 5, sizeof(float), compare);
time = clock() -time;
for(int i=0 ;i<5;i++)
cout<<array2[i]<<" ";
cout<<endl;
cout<<"Time for array2 - "<<time<<endl<<endl;

time = clock();
qsort(array3, 5, sizeof(char), cmpfunc);
time = clock() -time;
for(int i=0 ;i<5;i++)
cout<<array3[i]<<" ";
cout<<endl;
cout<<"Time for array3 - "<<time<<endl<<endl;

}


Related Solutions

I need the code for following in C++ working for Visual studio please. Thanks Use a...
I need the code for following in C++ working for Visual studio please. Thanks Use a Struct to create a structure for a Player. The Player will have the following data that it needs maintain: Struct Player int health int level string playerName double gameComplete bool isGodMode Create the 2 functions that will do the following: 1) initialize(string aPlayerName) which takes in a playername string and creates a Player struct health= 100 level= 1 playerName = aPlayerName gameComplete = 0...
Create a C++ project in visual studio. You can use the C++ project that I uploaded...
Create a C++ project in visual studio. You can use the C++ project that I uploaded to complete this project. 1. Write a function that will accept two integer matrices A and B by reference parameters, and two integers i and j as a value parameter. The function will return an integer m, which is the (i,j)-th coefficient of matrix denoted by A*B (multiplication of A and B). For example, if M = A*B, the function will return m, which...
Write a C program The Visual Studio project itself must make its output to the Console...
Write a C program The Visual Studio project itself must make its output to the Console (i.e. the Command Prompt using printf) and it must exhibit the following features as a minimum: 3%: Looping Menu with 3 main actions: View Cars, Sell Car, View Sales Note: A Car is defined by its price and model 3%: Must contain at least three arrays to record sales figures (maximum of 10 Car models) Two for recording the price and model of one...
MUST BE DONE IN C (NOT C++) Using an array and a function, print the values...
MUST BE DONE IN C (NOT C++) Using an array and a function, print the values of an array backwards. Please follow these guidelines: - Setup your array manually (whichever values you want, as many as you want and whichever datatype you prefer). - Call your function. You should send two parameters to such function: the array’s length and the array. - Inside the function, go ahead and print the array backwards. - Your function shouldn’t return anything
MUST BE DONE IN C (NOT C++) In this task, using a function, we will add...
MUST BE DONE IN C (NOT C++) In this task, using a function, we will add a range of values of an array. The range will be determined by the user. For example, if I have the following array … 1.5 -5.6 8.9 4.6 7.8 995.1 45.1 -5964.2 … and the user tells me to add from the 3rd element to the 6th element, my program would add the values 8.9, 4.6, 7.8 and 995.1. To do so, please follow...
All of these programs need IO. So you must use appropriate Visual Studio solution as the...
All of these programs need IO. So you must use appropriate Visual Studio solution as the template (windows32 has been provided in the book’s website and you supposed to know how to use it as it was required in the previous assignment) Write an assembly language program to calculate the following. (((((20 + 21) × 22) + 23)×24)+25 : : :) + 2n Hint: Note that when n is even, carrying result is multiplied by 2n. When n is odd,...
Write a C program of car sale: The Visual Studio project itself must make its output...
Write a C program of car sale: The Visual Studio project itself must make its output to the Console (i.e. the Command Prompt using printf) and it must exhibit the following features as a minimum: 10%: Looping Menu with 2 main actions: Sell Car, View Sales Note: A Car is defined only by its price 10% Must contain at least one array containing sales figures (each entry represents the price of one vehicle) for a maximum of 10 Cars 5%:...
MUST BE WRITTEN IN ASSEMBLY LANGUAGE ONLY AND MUST COMPILE IN VISUAL STUDIO You will write...
MUST BE WRITTEN IN ASSEMBLY LANGUAGE ONLY AND MUST COMPILE IN VISUAL STUDIO You will write a simple assembly language program that performs a few arithmetic operations. This will require you to establish your programming environment and create the capability to assemble and execute the assembly programs that are part of this course. Your \student ID number is a 7-digit number. Begin by splitting your student ID into two different values. Assign the three most significant digits to a variable...
(MUST BE DONE IN C (NOT C++)) For this program, remember to use feet and inches....
(MUST BE DONE IN C (NOT C++)) For this program, remember to use feet and inches. First, ask the user for the name of students they have in their class. Then, using a loop, you will ask for each student’s height. However, you will have to use two separate variables, one for feet and one for inches. Then, you will have to call two functions. The first function will check if the values entered are valid (check if number of...
I need a few unit tests done on my SelectionSort program in Visual Studio 2019 with...
I need a few unit tests done on my SelectionSort program in Visual Studio 2019 with MSTest. My program is below. I just need screen shots of the unit test code in Visual Studio 2019 with MSTest. Please and thank you. so easentially I need someone to write some unit tests with my program in MSTest visual studio 2019. Then I need the unit tests supplied as answers. using System; namespace SelectionSortAlgorithm { public class SelectionSort { public static void...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT