Skip to content

Instantly share code, notes, and snippets.

@yujuwon
Created July 1, 2013 00:55
Show Gist options
  • Select an option

  • Save yujuwon/5897726 to your computer and use it in GitHub Desktop.

Select an option

Save yujuwon/5897726 to your computer and use it in GitHub Desktop.
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