OJ5-2 B. Shell sort
輸入樣例文字版:
10
49,38,65,97,76,13,27,50,2,8,
#include <stdio.h>
#include <stdlib.h>
void shellSort(int a[], int n);
int main()
{
int n;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++)
{
scanf("%d,", &a[i]);
}
shellSort(a, n);
return 0;
}
void shellSort(int a[], int n)
{
int increment;
int i, j;
int temp;
for (increment = n / 2; increment >= 1; increment = increment / 2)
{
for (i = increment; i < n; i++)
{
temp = a[i];
for (j = i; j >= increment && temp > a[j - increment]; j = j - increment)
{
a[j] = a[j - increment];
}
a[j] = temp;
}
for (int k = 0; k < n; k++)
{
printf("%d,", a[k]);
}
printf("\n");
}
}
相關文章
- 希爾排序(Shell Sort)排序
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch SortIntelBAT
- Shell—擴充套件正規表示式(awk、sort、uniq、tr工具)套件
- Insertion Sort and Merge Sort
- B. 酒杯
- B. XOR = Average
- B. Range and Partition
- B. Aleksa and Stack
- B. Charming Meals
- B. AB Flipping
- B. Time Travel
- B. Array Fix
- B. Equal XOR
- B. Composite Coloring
- B. Quasi Binary
- B. Rudolf and 121
- B. Preparing Olympiad
- B. Find The Array
- B. Mashmokh and ACMACM
- B. Two Out of Three
- B. Nezzar and Binary String
- B. Missing Subsequence Sum
- B. Same Parity Summands
- topo sort
- sort排序排序
- Queue Sort
- JavaScript sort()JavaScript
- B. Numbers Box(思維)
- B. Navigation System【CF 1320】Navigation
- CF1455 B. Jumps
- golang sort.Sort () 排序演算法學習Golang排序演算法
- 關於stable_sort()和sort()的區別:
- sort()函式函式
- Leetcode Sort ColorsLeetCode
- Leetcode Sort ArrayLeetCode
- REPLACEMENT SELECTION SORT
- Sort Array By Parity
- Polyphase Merge Sort