Question: Hi, using the follwing code can someone implement the void routines for selection sort, insertion sort and quicksort, thanks #include #include #include using namespace std;

Hi, using the follwing code can someone implement the void routines for selection sort, insertion sort and quicksort, thanks

#include  #include  #include  using namespace std; long compares; // for counting compares long swaps; // for counting swaps bool counted_less(int n1, int n2) { ++compares; return n1  0) size = atoi(argv[0]); int* data = new int[size]; if (dataset == "already sorted") { for (int i = 0; i  

Hi, using the follwing code can someone implement the void routines for

selection sort, insertion sort and quicksort, thanks #include #include #include using namespace

Level 1: Basic Sorts Implement the selectionsort and insertionsort functions. Note that you can base your code on the the sample code used in lectures, although you'll need to change it from passing the data using an array and 2 indexes, to passing it using two pointers. Level 2: Quicksort Implement the quicksort function. The real work of quicksort happens in the partition operation, so it's probably best to define a separate function to do the partitioning. Level 3: Profiling For this checkpoint you need to gather data about the number of times that each algorithm compares or swaps items. A simple strategy is to use functions to do the comparisons and swaps, and then increment count variables inside the functions. The skeleton program provides the functions counted less and counted swap for just this purpose. To use them, modify your code to call the functions where appropriate, then uncomment the code that displays the final values of the count variables. The merge sort code shows the idea. Level 1: Basic Sorts Implement the selectionsort and insertionsort functions. Note that you can base your code on the the sample code used in lectures, although you'll need to change it from passing the data using an array and 2 indexes, to passing it using two pointers. Level 2: Quicksort Implement the quicksort function. The real work of quicksort happens in the partition operation, so it's probably best to define a separate function to do the partitioning. Level 3: Profiling For this checkpoint you need to gather data about the number of times that each algorithm compares or swaps items. A simple strategy is to use functions to do the comparisons and swaps, and then increment count variables inside the functions. The skeleton program provides the functions counted less and counted swap for just this purpose. To use them, modify your code to call the functions where appropriate, then uncomment the code that displays the final values of the count variables. The merge sort code shows the idea

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!