c语言排序英文名字,c语言经典排序算法(8种-含源代码)(国外英文资料).doc

c语言经典排序算法(8种-含源代码)(国外英文资料)

c语言经典排序算法(8种-含源代码)(国外英文资料)

A man is better than a man

Common classical sorting algorithm

1. Hill sorting

dichotomy

Direct insertion

Take the sentinel's direct collation

Bubble sort 5.

6. Select the sorting

7. Quick sort

8. Heap sort

A.hill (or, in the case of a small, small, incremental sort, which was brought up by D.L.S hell in 1959)

/ * Shell sort method * /

# include < stdio, h >

Void sort (int v [], int n)

{

Int gap, I, j, temp;

For (gap = n / 2; gap > 0; gap / = 2) / * set the sequence of steps for the length of the steps in half, until the gap is reduced to 1 * /

{

For (I = gap; I < n; I + +) / * to each element * /

{

For (j = I - gap; (j > = 0) && (v + gap [j] [j] > v); j - = gap) / * compare the size of the gap is far away from the two elements, according to the sort direction to decide how to switch * /

{

Temp = v [j];

V [j] = v [j + gap];

V + gap [j] = temp;

}

}

}

}

Binary interpolation

/ * binary insert method * /

Void HalfInsertSort (int a [], int len)

{

Int I, j, temp.

Int low, high, mid;

"For" (I = 1; I < len; I + +)

{

Temp = a [I]; / * save the pre-element * /

Low = 0;

High = I - 1;

While (low < = high) / * in a [low... high], find the location of an ordered insert * /

{

So, mid is low plus high over 2; / * find the middle element * /

If a [mid] > temp / * if the intermediate element is larger than the previous element, the current element is inserted into the left side of the intermediate element

{

High = mid - 1;

}

Else if the intermediate element is smaller than the current element, the previous element is inserted into the right side of the intermediate element

{

Low = mid + 1;

}

} / * find the location of the current element, between low and high * /

For (j = I - 1; j > high; j -) / *

{

A [j + 1] = a [j];

}

A [high + 1] = temp; / * insert * /

}

}

Three. Direct insertion

/ * directly insert method * /

So, void InsertionSort (int input, int len)

{

Int I, j, temp.

"For" (I = 1; I < len; I + +)

{

Temp = input [I]; / * manipulate the current element,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值