The power of C, the secret of MD
首先說明該排序演算法是抄維基百科的
梳排序(Comb sort)是一種由Wlodzimierz Dobosiewicz於1980年所發明的不穩定排序演算法,並由Stephen Lacey和Richard Box於1991年四月號的Byte雜誌中推廣。梳排序是改良自泡沫排序和快速排序,其要旨在於消除烏龜,亦即在陣列尾部的小數值,這些數值是造成泡沫排序緩慢的主因。相對地,兔子,亦即在陣列前端的大數值,不影響泡沫排序的效能。
在泡沫排序中,只比較陣列中相鄰的二項,即比較的二項的間距(Gap)是1,梳排序提出此間距其實可大於1,改自插入排序的希爾排序同樣提出相同觀點。梳排序中,開始時的間距設定為陣列長度,並在迴圈中以固定比率遞減,通常遞減率設定為1.3。在一次迴圈中,梳排序如同泡沫排序一樣把陣列從首到尾掃描一次,比較及交換兩項,不同的是兩項的間距不固定於1。如果間距遞減至1,梳排序假定輸入陣列大致排序好,並以泡沫排序作最後檢查及修正。
注:陣列也就是陣列了,是港臺那邊的術語。
演算法還是很簡單的,直接給出原始碼:
執行過程和結果如下,測試用例生成的隨機陣列大約進行10次左右的交換就能夠完成排序了:
相關推薦
The power of C, the secret of MD
首先說明該排序演算法是抄維基百科的 梳排序(Comb sort)是一種由Wlodzimierz Dobosiewicz於1980年所發明的不穩定排序演算法,並由Stephen Lacey和Richard Box於1991年四月號的Byte雜誌中推廣。梳排序是改良自泡沫排序
【背包專題】C - The trouble of Xiaoqian hdu3591【混合背包:多重背包+完全背包】
back 無法 name spa int receive with out man In the country of ALPC , Xiaoqian is a very famous mathematician. She is immersed in calculate,
CF 1005C Summarize to the Power of Two 【hash/STL-map】
eric bre rom delete there set while == [] A sequence a1,a2,…,an is called good if, for each element ai, there exists an element aj (i≠j)
Summarize to the Power of Two(map+思維)
fin bsp you -i 出現次數 出現 exists rst init A sequence a1,a2,…,ana1,a2,…,an is called good if, for each element aiai,
the struct of c lauguage test code
#include <stdio.h> typedef struct i { int a; char b;
揭開深度跟蹤的力量--Unveiling the Power of Deep Tracking (ECCV2018)
論文地址:Goutam_Bhat_Unveiling_the_Power_ECCV_2018_paper 文章亮點: 1、分析深度特徵和淺層特徵對跟蹤器效能的影響; 2、探究跟蹤器魯棒性和準確性之間的平衡; 3、提出新的深淺特徵的融合策略; 另:研究資料增強策略
論文筆記 Combining the Power of Internal and External Denoising
論文筆記 Combining the Power of Internal and External Denoising IEEE論文地址: https://ieeexplore.ieee.org/document/6528298 abstract 這篇論文是我在閱讀上一篇論文,影
1005C Summarize to the Power of Two (貪心 + 煞筆的我寫了一發離散化)
Summarize to the Power of Two 題意:給定一個數組,問陣列中每一個元素 a[i] , 是否存在另一個元素 a[j], 使 a[i] + a[j] 是 2 的次冪, i != j 思路:貪心,先打出足夠的
On the power of technologic icebreakers, a UX case study on how adults and teens could write…
On the power of technologic icebreakers, a UX case study on how adults and teens could write stories together with hashtags.Designing for familiesFor my fi
Kotlin Demystified: The power of `when`
I have a confession. I’m a bit of a gamer. The Legend of Zelda games are particular favorites. Imagine my excitement when I learned there were “randomizers
Nobel Prize in Chemistry 2018: Harnessing the power of evolution
They harnessed the power of evolution The power of evolution is revealed through the diversity of life. The 2018 Nobel Laureates in Chemistry have taken c
Harness the Power of Augmented Reality with Camera Effects Platform
Facebook has long been a place where people connect and communicate with one another by sharing personal stories, photos, and videos about their lives. Las
5 App Ideas to Unleash the Power of Mobile Machine Learning
With over 2 billion active Android devices and over 1 billion active iOS users, the mobile market provides the most engaging and profitable market to build
The Power of Goal-Setting in Data Science
Apply OKRs to your Data Science projectAndrew Ng, the famous AI-pioneer, teaches in his Deep Learning Specialization that every Data Science project should
The Power of Voice: Amazon Alexa (Part 1)
While undertaking new concept development within the Anthemis Foundry, I couldn’t resist tapping into the possibilities of voice interfaces across industri
Unleash the power of Slack App
1. Create NodeJS serverCreate a new NodeJS project by following these steps:Update package.json with the following content. This step is important for the
Scott Amyx Speaking on the Power of AI Data Analytics (Video)
All of you play a critical role in the regional and national economy. Small businesses and family owned businesses are the backbone of this country. In ord
The power of scratching your own itch
The power of scratching your own itchTo build a successful product, you also have to USE itOriginally published on JOTFORM.COMThe best business ideas usual
The power of doing nothing at all
The power of doing nothing at allOriginally published on JOTFORM.COMThe old crocodile was floating at the river’s edge when a younger crocodile swam up nex