Created
July 1, 2013 00:55
-
-
Save yujuwon/5897726 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const int ITEMSIZE = 6; | |
| void shell_sort(int array[],int length){ | |
| int i,j,k,tempInt; | |
| int interval = length; | |
| do { | |
| interval = interval/2; // Shell 정렬 간격 설정. | |
| for (i=0; i<interval; i++){ // 인터벌 개수까지만 루프를 실행. | |
| for (j=i+interval; i<length; i+=interval){ // 삽입 정렬. 차이점이라면 인터벌 개수를 기점으로 돌린다는 차이. | |
| tempInt = num[j]; | |
| for(k=i; num[k] > tempInt && k>=0; k-=interval){ | |
| num[j] = num[k]; | |
| } | |
| num[j] = tempInt; | |
| } | |
| } | |
| } while (interval >= 1); | |
| } | |
| int main(void){ | |
| int array[itemSize] = {3, 8, 0, 2, 1, 4}; | |
| shell_sort(array,ITEMSIZE); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment