|
Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
|
Comb Sort Algorithm (Comb Sort) More...
#include <algorithm>#include <cassert>#include <iostream>Functions | |
| int | FindNextGap (int gap) |
| void | CombSort (int *arr, int l, int r) |
| void | tests () |
| int | main () |
Comb Sort Algorithm (Comb Sort)
| void CombSort | ( | int * | arr, |
| int | l, | ||
| int | r | ||
| ) |
Function to sort array
| arr | array to be sorted |
| l | start index of array |
| r | end index of array |
initial gap will be maximum and the maximum possible value is the size of the array that is n and which is equal to r in this case so to avoid passing an extra parameter n that is the size of the array we are using r to initialize the initial gap.
Initialize swapped as true to make sure that loop runs
Keep running until gap = 1 or none elements were swapped
Find next gap
Compare all elements with current gap
| int FindNextGap | ( | int | gap | ) |
| int main | ( | void | ) |
Main function
Running predefined tests
For user interaction
| void tests | ( | ) |
Test 1
Test 2