TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Comb Sort Algorithm (Comb Sort) More...
#include <algorithm>
#include <cassert>
#include <iostream>
Go to the source code of this file.
Functions | |
int | FindNextGap (int gap) |
void | CombSort (int *arr, int l, int r) |
void | tests () |
int | main () |
Comb Sort Algorithm (Comb Sort)
Definition in file comb_sort.cpp.
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
Definition at line 42 of file comb_sort.cpp.
int FindNextGap | ( | int | gap | ) |
Find the next gap by shrinking the current gap by shrink factor of 1.3
gap | current gap |
Definition at line 29 of file comb_sort.cpp.
int main | ( | void | ) |
Main function
Running predefined tests
For user interaction
Definition at line 88 of file comb_sort.cpp.
void tests | ( | ) |
Test 1
Test 2
Definition at line 73 of file comb_sort.cpp.