Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need Help on the functions at the bottom and the comb sort ive never seen or use

ID: 3745539 • Letter: N

Question

Need Help on the functions at the bottom and the comb sort ive never seen or used it before. I just need an example to see how to call one of each of the functions and I will finish the rest. Any help is appreciated thanks!

Assignment:

Design and implement a C++ program to read a type selection from the user (integer, float,

double, string, or quit) and for the numeric types, read a length from the user. For the numeric

types, generate length number of values stored in an array. The program should use overloaded

functions to generate the numeric values, determine the minimum, maximum, sort the data, and

display the results.

#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>

using namespace std;


// ****************************************************************
// Program specific constants.

enum allowedTypes {INTEGER, FLOAT, DOUBLE, STRING, NONE};

#define MIN_LENGTH 10
#define MAX_LENGTH 250
#define NUMSPERLINE 5
#define MAXVALUE 1000


// ****************************************************************

allowedTypes getOperation();
int getLength();

void generateList(int arr[], int n);
void generateList(float arr[], int n);
void generateList(double arr[], int n);

int maximum(int list[],int size);
float maximum(float list[], int size);
double maximum(double list[], int size);
string maximum(string list[], int size);

int minimum(int list[],int size);
float minimum(float list[], int size);
double minimum(double list[], int size);
string minimum(string list[], int size);

void displayResults(int arr[], int max, int min, int n);
void displayResults(float arr[], float max, float min, int n);
void displayResults(double arr[], double max, double min, int n);
void displayResults(string arr[], string max, string min, int n);

void combSort(int arr[], int size);
void combSort(float arr[], int size);
void combSort(double arr[], int size);
void combSort(string arr[], int size);


// ****************************************************************

int main()
{
// --------------------------------------------
// Data declarations
//    includes arrays for each of the various types.

      int   iNums[MAX_LENGTH];
      int   imin, imax;

      float fNums[MAX_LENGTH];
      float fmin, fmax;

      double      dNums[MAX_LENGTH];
      double      dmin, dmax;

      string      sWords[] = {"hat", "tree", "window", "Door", "house", "flower",
                        "pencil", "desk", "cup", "coffee", "tea",
                        "sugar", "salt", "pepper", "ring", "number",
                        "computer", "day", "Year", "Day", "Month",
                        "key", "dog", "Fred", "Air", "Coat", "shoe",
                        "television", "candle", "rock", "Paper", "Lizard"};
      string      smin, smax;

      allowedTypes      myType;
      int   length;

// --------------------------------------------
// Main processing loop
//    get type from user and
//    if needed, get length
//    if needed, generate data
//    get min and max
//    sort numbers
//    display data

      while (true) {

            myType = getOperation();

            if ( myType == INTEGER || myType == FLOAT || myType == DOUBLE )
                  length = getLength();

            if (myType == NONE) {
                  cout << endl << "Game over." << endl <<
                        "Thanks for playing." << endl;
                  break;
            }

            switch (myType) {
                  case INTEGER:
                        generateList(iNums, length);
                        imax = maximum(iNums, length);
                        imin = minimum(iNums, length);
                        combSort(iNums, length);
                        displayResults(iNums, imax, imin, length);
                        break;
                  case FLOAT:
                        generateList(fNums, length);
                        fmax = maximum(fNums, length);
                        fmin = minimum(fNums, length);
                        combSort(fNums, length);
                        displayResults(fNums, fmax, fmin, length);
                        break;
                  case DOUBLE:
                        generateList(dNums, length);
                        dmax = maximum(dNums, length);
                        dmin = minimum(dNums, length);
                        combSort(dNums, length);
                        displayResults(dNums, dmax, dmin, length);
                        break;
                  case STRING:
                        smax = maximum(sWords, sizeof(sWords)/sizeof(sWords[0]));
                        smin = minimum(sWords, sizeof(sWords)/sizeof(sWords[0]));
                        combSort(sWords, sizeof(sWords)/sizeof(sWords[0]));
                        displayResults(sWords, smax, smin,
                              sizeof(sWords)/sizeof(sWords[0]));
                        break;
            }
      }

      return EXIT_SUCCESS;
}


// ****************************************************************
// Ask user for data type of the operation.
//    Must be integer, float, double, string, or quit

allowedTypes getOperation()
{
      char answer;
      allowedTypes myType;
      bool goodInput = false;

      while (!goodInput) {
            cout << "-------------------------------" << endl;
            cout << "Select data type for operations" << endl;
            cout << "     Integers (I/i)" << endl;
            cout << "     Floats (F/f)" << endl;
            cout << "     Doubles (D/d)" << endl;
            cout << "     Strings (S/s)" << endl;
            cout << "     Exit (Q/q)" << endl;
            cout << "Selection (I/i/F/f/D/d/S/s/Q/q): ";
            cin.clear();
            cin >> answer;

            switch (answer) {
                  case 'I':
                  case 'i':
                        myType = INTEGER;
                        goodInput = true;
                        break;
                  case 'F':
                  case 'f':
                        myType = FLOAT;
                        goodInput = true;
                        break;
                  case 'D':
                  case 'd':
                        myType = DOUBLE;
                        goodInput = true;
                        break;
                  case 'S':
                  case 's':
                        myType = STRING;
                        goodInput = true;
                        break;
                  case 'Q':
                  case 'q':
                        myType = NONE;
                        goodInput = true;
                        break;
                  default:
                        cout << "Error, must be I/i/F/f/D/d/S/s/Q/q " << endl;
                        cout << "Please re-enter." << endl;
            }
      }

      return myType;
}


// ****************************************************************
// Read and verify length from user.
//    Must be bewteen MIN_LENGTH and MAX_LENGTH (inclusive).
//    Routine shoud be efficient (which includes not performing
//          repeated, un-necessary work).

int   getLength()
{


}


// ****************************************************************
// Generate a list of random values.
//    uses rand() function (NO seed)
//    limits size to MAXVALUE

void generateList (int arr[], int n)
{

}

void generateList (float arr[], int n)
{

}

void generateList (double arr[], int n)
{

}


// ****************************************************************
// Determine maximum.
//    Note, routines do NOT require data to be sorted

int maximum (int lst[], int size)
{

}

float maximum (float lst[], int size)
{

}

double maximum (double lst[], int size)
{

}

string maximum (string lst[], int size)
{

}

// ****************************************************************
// Determine minimum.
//    Note, routines do NOT require data to be sorted

int minimum (int lst[], int size)
{

}

float minimum (float lst[], int size)
{

}

double minimum (double lst[], int size)
{

}

string minimum (string lst[], int size)
{

}


// ****************************************************************
// Display formatted results -> integer.
//    formatting as per assignment specifications
//    displays NUMSPERLINE items per line

void displayResults (int lst[], int max, int min, int aSize)
{


}


// ****************************************************************
// Display formatted results -> float.
//    formatting as per assignment specifications
//    displays NUMSPERLINE items per line

void displayResults (float lst[], float max, float min, int size)
{


}


// ****************************************************************
// Display formatted results -> double.
//    formatting as per assignment specifications
//    displays NUMSPERLINE items per line

void displayResults (double lst[], double max, double min, int size)
{


}


// ****************************************************************
// Display formatted results -> string.
//    formatting as per assignment specifications
//    displays NUMSPERLINE items per line

void displayResults (string lst[], string max, string min, int size)
{


}


// ****************************************************************
// Sort data using comb sort.

void combSort(int arr[], int size)
{


}

void combSort(float arr[], int size)
{


}

void combSort(double arr[], int size)
{


}


void combSort(string arr[], int size)
{


}


Use the following comb

1

sort algorithm:

function combsort(inputArray)

    gap := inputArray.size

// init gap size

    loop until gap = 1 and swapped = false

        // update the gap value for a next comb

        gap := int(gap / 1.247330950103979)

        if gap < 1

          //minimum gap is 1

          gap := 1

        end if

        i := 0

        swapped := false

        //a single "comb" over the input list

        loop until i + gap >= inputArray.size

            if input[i] > input[i+gap]

swap

(input[i], input[i+gap])

                swapped := true

// Flag a swap has occurred, so

// list is not yet fully sorted

            end if

            i := i + 1

        end loop

    end loop

end function

Example Execution:

Below is an example program execution.

Select data type for operations

     Integers (I/i)

     Floats (F/f)

     Doubles (D/d)

     Strings (S/s)

     Exit (Q/q)

Selection (I/i/F/f/D/d/S/s/Q/q): i

Enter Length: 14

----------------------------------------------

Integer Input Data (sorted):

27 59 335 362 383

386 421 492 649 690

777 793 886 915

The smallest integer value is 27.

The largest integer value is 915.

-------------------------------

Select data type for operations

     Integers (I/i)

     Floats (F/f)

     Doubles (D/d)

     Strings (S/s)

     Exit (Q/q)

Selection (I/i/F/f/D/d/S/s/Q/q): I

Enter Length: 77

----------------------------------------------

Integer Input Data (sorted):

11 22 42 43 58

67 69 84 87 91

123 124 135 167 170

172 178 198 211 229

276 281 305 313 315

324 327 336 364 367

368 370 373 393 399

403 413 421 426 429

434 456 505 526 530

537 540 545 567 582

584 651 729 736 750

754 763 782 784 788

802 808 814 846 857

862 862 873 895 919

925 926 929 932 956

980 996

The smallest integer value is 11.

The largest integer value is 996.

-------------------------------

Select data type for operations

     Integers (I/i)

     Floats (F/f)

     Doubles (D/d)

     Strings (S/s)

     Exit (Q/q)

Selection (I/i/F/f/D/d/S/s/Q/q): F

Enter Length: 17

----------------------------------------------

Float Input Data (sorted):

12.00 60.00 94.00 97.00 226.00

368.00 378.00 434.00 467.00 539.00

570.00 586.00 601.00 676.00 739.00

795.00 902.00

The smallest float value is 12.00.

The largest float value is 902.00.

-------------------------------

Explanation / Answer

#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <time.h>
using namespace std;


// ****************************************************************
// Program specific constants.

enum allowedTypes {INTEGER, FLOAT, DOUBLE, STRING, NONE};

#define MIN_LENGTH 10
#define MAX_LENGTH 250
#define NUMSPERLINE 5
#define MAXVALUE 1000


// ****************************************************************
// Function prototype
allowedTypes getOperation();
int getLength();

void generateList(int arr[], int n);
void generateList(float arr[], int n);
void generateList(double arr[], int n);

int maximum(int list[],int size);
float maximum(float list[], int size);
double maximum(double list[], int size);
string maximum(string list[], int size);

int minimum(int list[],int size);
float minimum(float list[], int size);
double minimum(double list[], int size);
string minimum(string list[], int size);

void displayResults(int arr[], int max, int min, int n);
void displayResults(float arr[], float max, float min, int n);
void displayResults(double arr[], double max, double min, int n);
void displayResults(string arr[], string max, string min, int n);

void combSort(int arr[], int size);
void combSort(float arr[], int size);
void combSort(double arr[], int size);
void combSort(string arr[], int size);


// ****************************************************************
// main function definition
int main()
{
// --------------------------------------------
// Data declarations
// includes arrays for each of the various types.

int iNums[MAX_LENGTH];
int imin, imax;

float fNums[MAX_LENGTH];
float fmin, fmax;

double dNums[MAX_LENGTH];
double dmin, dmax;

string sWords[] = {"hat", "tree", "window", "Door", "house", "flower",
"pencil", "desk", "cup", "coffee", "tea",
"sugar", "salt", "pepper", "ring", "number",
"computer", "day", "Year", "Day", "Month",
"key", "dog", "Fred", "Air", "Coat", "shoe",
"television", "candle", "rock", "Paper", "Lizard"};
string smin, smax;

allowedTypes myType;
int length;

// --------------------------------------------
// Main processing loop
// get type from user and
// if needed, get length
// if needed, generate data
// get min and max
// sort numbers
// display data

while (true)
{
// Calls the function to get the operation type
myType = getOperation();

// Checks if operation type with enumeration constant
if ( myType == INTEGER || myType == FLOAT || myType == DOUBLE )
// Call the function accept the length and validates it
length = getLength();
// Checks if operation type is enumeration constant NONE
if (myType == NONE)
{
cout << endl << "Game over." << endl << "Thanks for playing." << endl;
break;
}// End of if condition

// Checks the operation type
switch (myType)
{
case INTEGER:
// Checks if the length is zero then invalid length
if(length != 0)
{
// Calls the function to generate integer array
generateList(iNums, length);
// Calls the function to find maximum value
imax = maximum(iNums, length);
// Calls the function to find minimum value
imin = minimum(iNums, length);
// Calls the function to sort the array
combSort(iNums, length);
// Calls the function to display information
displayResults(iNums, imax, imin, length);
}// End of if condition
break;
case FLOAT:
// Checks if the length is zero then invalid length
if(length != 0)
{
// Calls the function to generate float array
generateList(fNums, length);
// Calls the function to find maximum value
fmax = maximum(fNums, length);
// Calls the function to find minimum value
fmin = minimum(fNums, length);
// Calls the function to sort the array
combSort(fNums, length);
// Calls the function to display information
displayResults(fNums, fmax, fmin, length);
}// End of if condition
break;
case DOUBLE:
// Checks if the length is zero then invalid length
if(length != 0)
{
// Calls the function to generate double array
generateList(dNums, length);
// Calls the function to find maximum value
dmax = maximum(dNums, length);
// Calls the function to find minimum value
dmin = minimum(dNums, length);
// Calls the function to sort the array
combSort(dNums, length);
// Calls the function to display information
displayResults(dNums, dmax, dmin, length);
}// End of if condition
break;
case STRING:
// Calls the function to find maximum value
smax = maximum(sWords, sizeof(sWords)/sizeof(sWords[0]));
// Calls the function to find minimum value
smin = minimum(sWords, sizeof(sWords)/sizeof(sWords[0]));
// Calls the function to sort the array
combSort(sWords, sizeof(sWords)/sizeof(sWords[0]));
// Calls the function to display information
displayResults(sWords, smax, smin,sizeof(sWords)/sizeof(sWords[0]));
break;
}// End of switch - case
}// End of while loop
return EXIT_SUCCESS;
}// End of main function


// ****************************************************************
// Ask user for data type of the operation.
// Must be integer, float, double, string, or quit
allowedTypes getOperation()
{
char answer;
allowedTypes myType;
bool goodInput = false;
// Displays the menu
while (!goodInput)
{
cout << "-------------------------------" << endl;
cout << "Select data type for operations" << endl;
cout << " Integers (I/i)" << endl;
cout << " Floats (F/f)" << endl;
cout << " Doubles (D/d)" << endl;
cout << " Strings (S/s)" << endl;
cout << " Exit (Q/q)" << endl;
cout << "Selection (I/i/F/f/D/d/S/s/Q/q): ";
cin.clear();
cin >> answer;
// Checks the user choice
switch (answer)
{
case 'I':
case 'i':
myType = INTEGER;
goodInput = true;
break;
case 'F':
case 'f':
myType = FLOAT;
goodInput = true;
break;
case 'D':
case 'd':
myType = DOUBLE;
goodInput = true;
break;
case 'S':
case 's':
myType = STRING;
goodInput = true;
break;
case 'Q':
case 'q':
myType = NONE;
goodInput = true;
break;
default:
cout << "Error, must be I/i/F/f/D/d/S/s/Q/q " << endl;
cout << "Please re-enter." << endl;
}// End of switch - case
}// End of while loop
// Returns the choice
return myType;
}// End of function

// ****************************************************************
// Read and verify length from user.
// Must be between MIN_LENGTH and MAX_LENGTH (inclusive).
// Routine should be efficient (which includes not performing
// repeated, un-necessary work).
int getLength()
{
// To store length entered by the user
int len;
// Accepts the length
cout<<" Enter the length: ";
cin>>len;

// Checks if the length is between MIN_LENGTH and MAX_LENGTH
if(len >= MIN_LENGTH && len <= MAX_LENGTH)
// return length
return len;
// Otherwise display error message and return 0
else
{
cout<<" ERROR: Invalid length(Minimum - 10 Maximum - 250) ";
return 0;
}// End of else
}// End of function

// ****************************************************************
// Generate a list of random values.
// uses rand() function (NO seed)
// limits size to MAXVALUE

void generateList (int arr[], int n)
{
srand(time(NULL));
// Loops till array length
for(int x = 0; x < n; x++)
// Generates random integer number between 1 and MAXVALUE
arr[x] = rand() % MAXVALUE + 1;
}// End of function

void generateList (float arr[], int n)
{
srand(time(NULL));
// Loops till array length
for(int x = 0; x < n; x++)
// Generates random float number between 1.0f and MAXVALUE
arr[x] = rand() / (MAXVALUE + 1.0f);
}// End of function

void generateList (double arr[], int n)
{
srand(time(NULL));
// Loops till array length
for(int x = 0; x < n; x++)
// Generates random double number between 1.0 and MAXVALUE
arr[x] = rand() / (MAXVALUE + 1.0);
}// End of function


// ****************************************************************
// Determine maximum.
// Note, routines do NOT require data to be sorted
int maximum (int lst[], int size)
{
// Stores the starting value as maximum
int maxVal = lst[0];
// Loops till array length
for(int x = 1; x < size; x++)
{
// Checks if the current integer number is greater than the earlier maxVal
if(lst[x] > maxVal)
// Update the maxVal with current number
maxVal = lst[x];
}// End of for loop
// Returns the maximum number
return maxVal;
}// End of function

float maximum (float lst[], int size)
{
// Stores the starting value as maximum
float maxVal = lst[0];
// Loops till array length
for(int x = 1; x < size; x++)
{
// Checks if the current float number is greater than the earlier maxVal
if(lst[x] > maxVal)
// Update the maxVal with current number
maxVal = lst[x];
}// End of for loop
// Returns the maximum number
return maxVal;
}// End of function

double maximum (double lst[], int size)
{
// Stores the starting value as maximum
double maxVal = lst[0];
// Loops till array length
for(int x = 1; x < size; x++)
{
// Checks if the current double number is greater than the earlier maxVal
if(lst[x] > maxVal)
// Update the maxVal with current number
maxVal = lst[x];
}// End of for loop
// Returns the maximum number
return maxVal;
}// End of function

string maximum (string lst[], int size)
{
// Stores the starting value as maximum
int maxVal = lst[0].length();
string maxStr = lst[0];
cout<<size;
// Loops till array length
for(int x = 1; x < size; x++)
{
// Checks if the current string length is greater than the earlier maxVal
if(lst[x].length() > maxVal)
{
// Update the maxVal with current number
maxVal = lst[x].length();
// Assigns the current string as the maximum string
maxStr = lst[x];
}// End of if condition
}// End of for loop
// Returns the maximum string
return maxStr;
}// End of function

// ****************************************************************
// Determine minimum.
// Note, routines do NOT require data to be sorted
int minimum (int lst[], int size)
{
// Stores the starting value as minimum
int minVal = lst[0];
// Loops till array length
for(int x = 1; x < size; x++)
{
// Checks if the current integer number is less than the earlier minVal
if(lst[x] < minVal)
// Update the minVal with current number
minVal = lst[x];
}// End of for loop
// Returns the minimum number
return minVal;
}// End of function

float minimum (float lst[], int size)
{
// Stores the starting value as minimum
float minVal = lst[0];
// Loops till array length
for(int x = 1; x < size; x++)
{
// Checks if the current float number is less than the earlier minVal
if(lst[x] < minVal)
// Update the minVal with current number
minVal = lst[x];
}// End of for loop
// Returns the minimum number
return minVal;
}// End of function

double minimum (double lst[], int size)
{
// Stores the starting value as minimum
double minVal = lst[0];
// Loops till array length
for(int x = 1; x < size; x++)
{
// Checks if the current double number is less than the earlier minVal
if(lst[x] < minVal)
// Update the minVal with current number
minVal = lst[x];
}// End of for loop
// Returns the minimum number
return minVal;
}// End of function

string minimum (string lst[], int size)
{
// Stores the starting string length as minimum
int minVal = lst[0].length();
// Stores the starting string as minimum
string minStr = lst[0];
// Loops till array length
for(int x = 1; x < size; x++)
{
// Checks if the current string length is less than the earlier minVal
if(lst[x].length() < minVal)
{
// Update the minVal with current string length
minVal = lst[x].length();
// Assigns the current string as minimum string
minStr = lst[x];
}// End of if condition
}// End of for loop
// Returns the string
return minStr;
}// End of function


// ****************************************************************
// Display formatted results -> integer.
// formatting as per assignment specifications
// displays NUMSPERLINE items per line

void displayResults (int lst[], int max, int min, int aSize)
{
cout<<" Integer Input Data (sorted): ";
// Loops till array length
for(int x = 1; x <= aSize; x++)
// Checks if the loop counter is divisible by 5 then display number with new line
if(x % 5 == 0)
cout<<lst[x-1]<<endl;
// Otherwise display the number with tab space
else
cout<<lst[x-1]<<" ";
// Display the smallest and biggest data
cout<<" The smallest integer value is "<<min;
cout<<" The largest integer value is "<<max<<endl;
}// End of function


// ****************************************************************
// Display formatted results -> float.
// formatting as per assignment specifications
// displays NUMSPERLINE items per line

void displayResults (float lst[], float max, float min, int size)
{
cout<<" Float Input Data (sorted): ";
// Loops till array length
for(int x = 1; x <= size; x++)
// Checks if the loop counter is divisible by 5 then display number with new line
if(x % 5 == 0)
cout<<lst[x-1]<<endl;
// Otherwise display the number with tab space
else
cout<<lst[x-1]<<" ";
// Display the smallest and biggest data
cout<<" The smallest float value is "<<min;
cout<<" The largest float value is "<<max<<endl;
}// End of function


// ****************************************************************
// Display formatted results -> double.
// formatting as per assignment specifications
// displays NUMSPERLINE items per line

void displayResults (double lst[], double max, double min, int size)
{
cout<<" Double Input Data (sorted): ";
// Loops till array length
for(int x = 1; x <= size; x++)
// Checks if the loop counter is divisible by 5 then display number with new line
if(x % 5 == 0)
cout<<lst[x-1]<<endl;
// Otherwise display the number with tab space
else
cout<<lst[x-1]<<" ";
// Display the smallest and biggest data
cout<<" The smallest double value is "<<min;
cout<<" The largest double value is "<<max<<endl;
}// End of function


// ****************************************************************
// Display formatted results -> string.
// formatting as per assignment specifications
// displays NUMSPERLINE items per line

void displayResults (string lst[], string max, string min, int size)
{
cout<<" String Input Data (sorted): ";
// Loops till array length
for(int x = 1; x <= size; x++)
// Checks if the loop counter is divisible by 5 then display number with new line
if(x % 5 == 0)
cout<<lst[x-1]<<endl;
// Otherwise display the number with tab space
else
cout<<lst[x-1]<<" ";
// Display the smallest and biggest data
cout<<" The smallest string value is "<<min;
cout<<" The largest string value is "<<max<<endl;
}// End of function


// ****************************************************************
// Sort data using comb sort.
// To find gap between elements
int findNextGap(int gap)
{
// Shrink gap by Shrink factor
gap = (gap * 10) / 13;
// Checks if gap is less than one then return 1
if (gap < 1)
return 1;
// Otherwise return the gap
return gap;
}// End of function

void combSort(int lst[], int size)
{
// Initialize gap
int gap = size;

// Initialize swapped as true to make sure that loop runs
bool swapped = true;

// Keep running while gap is more than 1 and last iteration caused a swap
while (gap != 1 || swapped == true)
{
// Find next gap
gap = findNextGap(gap);

// Initialize swapped as false so that we can check if swap happened or not
swapped = false;

// Compare all elements with current gap
for (int x = 0; x < size - gap; x++)
{
if (lst[x] > lst[x + gap])
{
swap(lst[x], lst[x + gap]);
swapped = true;
}// End of if condition
}// End of for loop
}// End of while loop
}// End of function

void combSort(float lst[], int size)
{
// Initialize gap
int gap = size;

// Initialize swapped as true to make sure that loop runs
bool swapped = true;

// Keep running while gap is more than 1 and last iteration caused a swap
while (gap != 1 || swapped == true)
{
// Find next gap
gap = findNextGap(gap);

// Initialize swapped as false so that we can check if swap happened or not
swapped = false;

// Compare all elements with current gap
for (int x = 0; x < size - gap; x++)
{
if (lst[x] > lst[x + gap])
{
swap(lst[x], lst[x + gap]);
swapped = true;
}// End of if condition
}// End of for loop
}// End of while loop
}// End of function

void combSort(double lst[], int size)
{
// Initialize gap
int gap = size;

// Initialize swapped as true to make sure that loop runs
bool swapped = true;

// Keep running while gap is more than 1 and last iteration caused a swap
while (gap != 1 || swapped == true)
{
// Find next gap
gap = findNextGap(gap);

// Initialize swapped as false so that we can check if swap happened or not
swapped = false;

// Compare all elements with current gap
for (int x = 0; x < size - gap; x++)
{
if (lst[x] > lst[x + gap])
{
swap(lst[x], lst[x + gap]);
swapped = true;
}// End of if condition
}// End of for loop
}// End of while loop
}// End of function


void combSort(string lst[], int size)
{
// Initialize gap
int gap = size;

// Initialize swapped as true to make sure that loop runs
bool swapped = true;

// Keep running while gap is more than 1 and last iteration caused a swap
while (gap != 1 || swapped == true)
{
// Find next gap
gap = findNextGap(gap);

// Initialize swapped as false so that we can check if swap happened or not
swapped = false;

// Compare all elements with current gap
for (int x = 0; x < size - gap; x++)
{
if (lst[x] > lst[x + gap])
{
swap(lst[x], lst[x + gap]);
swapped = true;
}// End of if condition
}// End of for loop
}// End of while loop
}// End of function

Sample Output:

-------------------------------
Select data type for operations
Integers (I/i)
Floats (F/f)
Doubles (D/d)
Strings (S/s)
Exit (Q/q)
Selection (I/i/F/f/D/d/S/s/Q/q): i

Enter the length: 5

ERROR: Invalid length(Minimum - 10 Maximum - 250)
-------------------------------
Select data type for operations
Integers (I/i)
Floats (F/f)
Doubles (D/d)
Strings (S/s)
Exit (Q/q)
Selection (I/i/F/f/D/d/S/s/Q/q): I

Enter the length: 10

Integer Input Data (sorted):
18 73 97 225 388
439 453 674 699 860

The smallest integer value is 18
The largest integer value is 860
-------------------------------
Select data type for operations
Integers (I/i)
Floats (F/f)
Doubles (D/d)
Strings (S/s)
Exit (Q/q)
Selection (I/i/F/f/D/d/S/s/Q/q): f

Enter the length: 15

Float Input Data (sorted):
1.56743 2.0959 4.33067 12.3487 15.0819
18.8392 21.1888 25.1009 26.0979 28.3157
28.3227 29.5405 29.7073 31.045 32.2128

The smallest float value is 1.56743
The largest float value is 32.2128
-------------------------------
Select data type for operations
Integers (I/i)
Floats (F/f)
Doubles (D/d)
Strings (S/s)
Exit (Q/q)
Selection (I/i/F/f/D/d/S/s/Q/q): D

Enter the length: 22

Double Input Data (sorted):
0.173826 2.12587 3.38861 4.72727 5.32268
5.67932 15.4665 15.5295 15.6843 15.7802
16.992 17.1279 22.5734 23.2058 23.4016
24.5315 25.5784 27.7403 28.2108 29.5514
30.8851 31.3816
The smallest double value is 0.173826
The largest double value is 31.3816
-------------------------------
Select data type for operations
Integers (I/i)
Floats (F/f)
Doubles (D/d)
Strings (S/s)
Exit (Q/q)
Selection (I/i/F/f/D/d/S/s/Q/q): s
32
String Input Data (sorted):
Air Coat Day Door Fred
Lizard Month Paper Year candle
coffee computer cup day desk
dog flower hat house key
number pencil pepper ring rock
salt shoe sugar tea television
tree window
The smallest string value is hat
The largest string value is television
-------------------------------
Select data type for operations
Integers (I/i)
Floats (F/f)
Doubles (D/d)
Strings (S/s)
Exit (Q/q)
Selection (I/i/F/f/D/d/S/s/Q/q): Q

Game over.
Thanks for playing.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote