Untitled
raw download clone
CPP
views 12
,
size 754 b
#include <iostream>
using namespace std;

void xuatmang(int arr[], int n){
	for(int i = 0; i < n; ++i){
		cout << arr[i] << " ";
	}
	cout << endl;
}

int getNumberGap(int n){
	int gap = n*10/13;
	
	if(n < 1){
		return 1;
	}
	return gap;
}

void comboSort(int arr[], int n){
	
	int gap = n;
	
	bool swapped = true;
	
	while(gap != 1 || swapped == true){
		
		gap = getNumberGap(gap);
		
		swapped = false;
		
		for(int i = 0; i < n-gap; ++i){
			if(arr[i] < arr[i+gap]){
				swap(arr[i], arr[i+gap]);
				swapped = true;
			}
		}
	}
	
}

int main(){
	int arr[] = {20, 15, 1, 30, 8, 9, 7, 3, 14, 6};
	int n = sizeof(arr) / sizeof(arr[0]);
	xuatmang(arr, n);
	comboSort(arr, n);
	xuatmang(arr,n);
	return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.