SWUST OJ 1099: C++ Implementation of Hill Sorting Algorithm

topic description

Program to implement the Hill sorting algorithm, according to non-decreasing sorting, the test data is an integer.

enter

The first line is the number n of data elements to be sorted; 
the second line is the data elements to be sorted.

output

The result of a Hill sort.
#include<bits/stdc++.h>
using namespace std;
int n, a[105], m;
int main(){
	cin>>n;
	m = n / 2;
	for(int i = 0; i < n; i++) cin>>a[i];
	for(int i = 0; i < n/ 2; i++) if(a[i]>a[i+m]) swap(a[i],a[i+m]);
	for(int i = 0; i < n; i++) cout<<a[i]<<" ";
	return 0;
}

 

Guess you like

Origin blog.csdn.net/Ljy_Cxy/article/details/131472062